[Beeframework-svn] SF.net SVN: beeframework:[53] trunk
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2013-08-19 22:16:35
|
Revision: 53
http://sourceforge.net/p/beeframework/code/53
Author: m_plomer
Date: 2013-08-19 22:16:31 +0000 (Mon, 19 Aug 2013)
Log Message:
-----------
- method-invocation extension for Context
Modified Paths:
--------------
trunk/framework/Bee/Context/Abstract.php
trunk/framework/Bee/Context/Config/BeanDefinition/Abstract.php
trunk/framework/Bee/Context/Config/BeanDefinition/Generic.php
trunk/framework/Bee/Context/Config/IBeanDefinition.php
trunk/framework/Bee/Context/Support/BeanUtils.php
trunk/framework/Bee/Context/Xml/ParserDelegate.php
trunk/framework/bee-beans-1.2.xsd
Added Paths:
-----------
trunk/framework/Bee/Beans/MethodInvocation.php
trunk/framework/Bee/Context/Config/IMethodArguments.php
trunk/framework/Bee/Context/Config/MethodArgumentsHolder.php
Removed Paths:
-------------
trunk/examples/vendor/
Added: trunk/framework/Bee/Beans/MethodInvocation.php
===================================================================
--- trunk/framework/Bee/Beans/MethodInvocation.php (rev 0)
+++ trunk/framework/Bee/Beans/MethodInvocation.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -0,0 +1,50 @@
+<?php
+namespace Bee\Beans;
+/*
+ * Copyright 2008-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+use Bee\Context\Config\IMethodArguments;
+use Bee\Context\Config\MethodArgumentsHolder;
+use Bee_Beans_PropertyValue;
+
+class MethodInvocation extends MethodArgumentsHolder implements IMethodArguments {
+
+ /**
+ * @var string
+ */
+ private $methodName;
+
+ /**
+ * @param string $methodName
+ */
+ function __construct($methodName) {
+ $this->methodName = $methodName;
+ }
+
+ /**
+ * @param string $methodName
+ */
+ public function setMethodName($methodName) {
+ $this->methodName = $methodName;
+ }
+
+ /**
+ * @return string
+ */
+ public function getMethodName() {
+ return $this->methodName;
+ }
+}
Modified: trunk/framework/Bee/Context/Abstract.php
===================================================================
--- trunk/framework/Bee/Context/Abstract.php 2013-08-19 12:58:55 UTC (rev 52)
+++ trunk/framework/Bee/Context/Abstract.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -1,4 +1,5 @@
<?php
+use Bee\Beans\MethodInvocation;
/*
* Copyright 2008-2010 the original author or authors.
*
@@ -203,6 +204,7 @@
try {
$this->applyPropertyValues($beanName, $beanDefinition, $instanceWrapper, $beanDefinition->getPropertyValues());
+ $this->invokeMethods($beanName, $beanInstance, $beanDefinition->getMethodInvocations());
$exposedObject = $this->initializeBean($beanName, $beanInstance, $beanDefinition);
} catch (Exception $ex) {
if ($ex instanceof Bee_Context_BeanCreationException && $beanName === $ex->getBeanName()) {
@@ -253,7 +255,7 @@
if (is_null($beanDefinition) || !$beanDefinition->isSynthetic()) {
$wrappedBean = $this->applyBeanPostProcessorsBeforeInitialization($wrappedBean, $beanName);
}
-
+
try {
$this->invokeInitMethods($beanName, $wrappedBean, $beanDefinition);
} catch (Exception $ex) {
@@ -412,15 +414,13 @@
return $beanClass->newInstanceArgs($this->createArgsArray($beanName, $beanDefinition));
}
-
-
- private function createArgsArray($beanName, Bee_Context_Config_IBeanDefinition $beanDefinition) {
+ private function createArgsArray($beanName, \Bee\Context\Config\IMethodArguments $methodArguments) {
// $typeConverter = null; // @todo: ???????????????????????????????????????????
// $valueResolver = new Bee_Context_BeanDefinitionValueResolver($this, $beanName, $beanDefinition, $typeConverter);
- $valueResolver = new Bee_Context_BeanDefinitionValueResolver($this, $beanName, $beanDefinition);
+ $valueResolver = new Bee_Context_BeanDefinitionValueResolver($this, $beanName, $methodArguments);
$args = array();
- foreach ($beanDefinition->getConstructorArgumentValues() as $propValue) {
+ foreach ($methodArguments->getConstructorArgumentValues() as $propValue) {
// $value = $valueResolver->resolveValueIfNecessary('constructor/factory method argument', $propValue->getValue());
// $args[] = $typeConverter->convertIfNecessary($value, $propValue->getTypeName());
$args[] = $valueResolver->resolveValueIfNecessary('constructor/factory method argument', $propValue->getValue());
@@ -428,8 +428,6 @@
return $args;
}
-
-
/**
* Apply the given property values, resolving any runtime references
* to other beans in this context.
@@ -459,6 +457,22 @@
}
}
+ /**
+ * @param $beanName
+ * @param $beanInstance
+ * @param MethodInvocation[] $methodInvocations
+ */
+ protected function invokeMethods($beanName, $beanInstance, array $methodInvocations = array()) {
+ foreach($methodInvocations as $methodInvocation) {
+ $method = array($beanInstance, $methodInvocation->getMethodName());
+ if(!is_callable($method)) {
+ throw new Bee_Context_InvalidPropertyException($methodInvocation->getMethodName(), Bee_Utils_Types::getType($beanInstance), 'no such method found: '.$methodInvocation->getMethodName());
+ }
+ // todo: validate method signature??
+ call_user_func_array($method, $this->createArgsArray($beanName, $methodInvocation));
+ }
+ }
+
abstract protected function loadBeanDefinitions();
/**
@@ -858,6 +872,4 @@
function getModificationTimestamp() {
return $this->context->getModificationTimestamp();
}
-}
-
-?>
\ No newline at end of file
+}
\ No newline at end of file
Modified: trunk/framework/Bee/Context/Config/BeanDefinition/Abstract.php
===================================================================
--- trunk/framework/Bee/Context/Config/BeanDefinition/Abstract.php 2013-08-19 12:58:55 UTC (rev 52)
+++ trunk/framework/Bee/Context/Config/BeanDefinition/Abstract.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -14,6 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+use Bee\Beans\MethodInvocation;
+use Bee\Context\Config\MethodArgumentsHolder;
/**
* Enter description here...
@@ -21,7 +23,7 @@
* @author Benjamin Hartmann
* @author Michael Plomer <mic...@it...>
*/
-abstract class Bee_Context_Config_BeanDefinition_Abstract implements Bee_Context_Config_IBeanDefinition {
+abstract class Bee_Context_Config_BeanDefinition_Abstract extends MethodArgumentsHolder implements Bee_Context_Config_IBeanDefinition {
/**
* String representation of the scope that this bean should live in.
@@ -56,21 +58,17 @@
*/
private $dependsOn = array();
-
/**
* Enter description here...
*
- * @var Bee_Beans_PropertyValue[]
+ * @var Bee_Beans_PropertyValue[] array of PropertyValue instances
*/
- private $constructorArgumentValues = array();
-
+ private $propertyValues = array();
/**
- * Enter description here...
- *
- * @var Bee_Beans_PropertyValue[] array of PropertyValue instances
+ * @var MethodInvocation[]
*/
- private $propertyValues = array();
+ private $methodInvocations = array();
/**
* Name of the factory bean, if this bean should be obtained by using another bean instance from the container as its factory.
@@ -137,6 +135,7 @@
$this->setAbstract($original->isAbstract());
$this->setConstructorArgumentValues($original->getConstructorArgumentValues());
$this->setPropertyValues($original->getPropertyValues());
+ $this->setMethodInvocations($original->getMethodInvocations());
$this->setDependsOn($original->getDependsOn());
$this->setInitMethodName($original->getInitMethodName());
$this->setEnforceInitMethod($original->isEnforceInitMethod());
@@ -159,12 +158,10 @@
return $this->beanClassName;
}
-
public function setBeanClassName($beanClassName) {
$this->beanClassName = $beanClassName;
}
-
/**
* Set if this bean is "abstract", i.e. not meant to be instantiated itself but
* rather just serving as parent for concrete child bean definitions.
@@ -199,42 +196,7 @@
public function setDependsOn(array $dependsOn) {
$this->dependsOn = $dependsOn;
}
-
-
- public function getConstructorArgumentValues() {
- return $this->constructorArgumentValues;
- }
-
-
- public function setConstructorArgumentValues(array $args) {
- $this->constructorArgumentValues = $args;
- }
-
- public function addConstructorArgumentValues(array $args) {
- foreach($args as $arg) {
- $this->addConstructorArgumentValue($arg);
- }
- }
-
- public function addConstructorArgumentValue(Bee_Beans_PropertyValue $arg) {
- $idx = $arg->getName();
- if(!is_int($idx) || $idx < 0) {
- trigger_error("Constructor argument index is not an integer or lower than 0 : $idx", E_USER_ERROR);
- } else {
- if(array_key_exists($idx, $this->constructorArgumentValues)) {
- $this->mergePropertyValuesIfPossible($this->constructorArgumentValues[$idx], $arg);
- }
- $this->constructorArgumentValues[$idx] = $arg;
- }
- }
-
- private function mergePropertyValuesIfPossible (Bee_Beans_PropertyValue $parent, Bee_Beans_PropertyValue $child) {
- $childValue = $child->getValue();
- if($childValue instanceof Bee_Context_Config_IMergeable && $childValue->getMergeEnabled() && $parent->getValue() instanceof Traversable) {
- $childValue->merge($parent->getValue());
- }
- }
-
+
public function getPropertyValues() {
return $this->propertyValues;
}
@@ -255,14 +217,44 @@
trigger_error("Property must have a name set", E_USER_ERROR);
} else {
if(array_key_exists($name, $this->propertyValues)) {
- $this->mergePropertyValuesIfPossible($this->propertyValues[$name], $prop);
+ Bee_Context_Support_BeanUtils::mergePropertyValuesIfPossible($this->propertyValues[$name], $prop);
}
$this->propertyValues[$name] = $prop;
}
return $this;
}
-
+ /**
+ * @return MethodInvocation[]
+ */
+ public function getMethodInvocations() {
+ return $this->methodInvocations;
+ }
+
+ /**
+ * @param MethodInvocation[] $methodInvocations
+ */
+ public function setMethodInvocations(array $methodInvocations) {
+ $this->methodInvocations = $methodInvocations;
+ }
+
+ /**
+ * @param MethodInvocation[] $methodInvocations
+ */
+ public function addMethodInvocations(array $methodInvocations) {
+ foreach($methodInvocations as $invocation) {
+ $this->addMethodInvocation($invocation);
+ }
+ }
+
+ /**
+ * @param MethodInvocation $methodInvocation
+ * @return void
+ */
+ public function addMethodInvocation(MethodInvocation $methodInvocation) {
+ array_push($this->methodInvocations, $methodInvocation);
+ }
+
public function getFactoryBeanName() {
return $this->factoryBeanName;
}
@@ -389,6 +381,7 @@
$this->setAbstract($other->isAbstract());
$this->addConstructorArgumentValues($other->getConstructorArgumentValues());
$this->addPropertyValues($other->getPropertyValues());
+ $this->addMethodInvocations($other->getMethodInvocations());
$this->addDependsOn($other->getDependsOn());
if(!is_null($other->getInitMethodName())) {
@@ -404,6 +397,4 @@
$this->setSynthetic($other->isSynthetic());
}
-}
-
-?>
\ No newline at end of file
+}
\ No newline at end of file
Modified: trunk/framework/Bee/Context/Config/BeanDefinition/Generic.php
===================================================================
--- trunk/framework/Bee/Context/Config/BeanDefinition/Generic.php 2013-08-19 12:58:55 UTC (rev 52)
+++ trunk/framework/Bee/Context/Config/BeanDefinition/Generic.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+use Bee\Beans\MethodInvocation;
/**
* Enter description here...
@@ -74,5 +75,3 @@
echo '<hr/>';
}
}
-
-?>
\ No newline at end of file
Modified: trunk/framework/Bee/Context/Config/IBeanDefinition.php
===================================================================
--- trunk/framework/Bee/Context/Config/IBeanDefinition.php 2013-08-19 12:58:55 UTC (rev 52)
+++ trunk/framework/Bee/Context/Config/IBeanDefinition.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+use Bee\Beans\MethodInvocation;
/**
* Enter description here...
@@ -21,7 +22,7 @@
* @author Benjamin Hartmann
* @author Michael Plomer <mic...@it...>
*/
-interface Bee_Context_Config_IBeanDefinition {
+interface Bee_Context_Config_IBeanDefinition extends Bee\Context\Config\IMethodArguments {
const SCOPE_CACHE = 'cache';
const SCOPE_SESSION = 'session';
@@ -35,7 +36,6 @@
*/
public function getParentName();
-
/**
* Set the name of the parent definition of this bean definition, if any.
*
@@ -55,8 +55,6 @@
*/
public function getBeanClassName();
-
-
/**
* Override the bean class name of this bean definition.
* <p>The class name can be modified during bean factory post-processing,
@@ -67,8 +65,6 @@
*/
public function setBeanClassName($beanClassName);
-
-
/**
* Return the factory bean name, if any.
*
@@ -76,8 +72,6 @@
*/
public function getFactoryBeanName();
-
-
/**
* Specify the factory bean to use, if any.
*
@@ -86,8 +80,6 @@
*/
public function setFactoryBeanName($factoryBeanName);
-
-
/**
* Return a factory method, if any.
*
@@ -95,8 +87,6 @@
*/
public function getFactoryMethodName();
-
-
/**
* Specify a factory method, if any. This method will be invoked with
* constructor arguments, or with no arguments if none are specified.
@@ -110,8 +100,6 @@
*/
public function setFactoryMethodName($factoryMethodName);
-
-
/**
* Override the target scope of this bean, specifying a new scope name.
* @see #SCOPE_SINGLETON
@@ -120,9 +108,7 @@
* @return String
*/
public function getScope();
-
-
-
+
/**
* Enter description here...
*
@@ -130,28 +116,8 @@
* @return void
*/
public function setScope($scope);
-
-
-
- /**
- * Return the constructor argument values for this bean.
- * <p>The returned instance can be modified during bean factory post-processing.
- *
- * @return Bee_Beans_PropertyValue[]
- */
- public function getConstructorArgumentValues();
-
/**
- * Enter description here...
- *
- * @param Bee_Beans_PropertyValue $arg
- * @return void
- */
- public function addConstructorArgumentValue(Bee_Beans_PropertyValue $arg);
-
-
- /**
* Return the property values to be applied to a new instance of the bean.
* <p>The returned instance can be modified during bean factory post-processing.
*
@@ -159,7 +125,6 @@
*/
public function getPropertyValues();
-
/**
* Add a PropertyValue object, replacing any existing one
* for the corresponding property.
@@ -169,17 +134,25 @@
* PropertyValues in a single statement
*/
public function addPropertyValue(Bee_Beans_PropertyValue $prop);
-
-
+
/**
+ * @return MethodInvocation[]
+ */
+ public function getMethodInvocations();
+
+ /**
+ * @param MethodInvocation $methodInvocation
+ * @return void
+ */
+ public function addMethodInvocation(MethodInvocation $methodInvocation);
+
+ /**
* Return whether this bean is "abstract", that is, not meant to be instantiated.
*
* @return boolean
*/
public function isAbstract();
-
-
/**
* Enter description here...
*
@@ -187,8 +160,6 @@
*/
public function getDependsOn();
-
-
/**
* Enter description here...
*
@@ -196,8 +167,6 @@
*/
public function setDependsOn(array $dependsOn);
-
-
/**
* Enter description here...
*
@@ -206,8 +175,6 @@
*/
public function setInitMethodName($initMethodName);
-
-
/**
* Enter description here...
*
@@ -274,6 +241,4 @@
* @return boolean
*/
public function isSynthetic();
-}
-
-?>
\ No newline at end of file
+}
\ No newline at end of file
Added: trunk/framework/Bee/Context/Config/IMethodArguments.php
===================================================================
--- trunk/framework/Bee/Context/Config/IMethodArguments.php (rev 0)
+++ trunk/framework/Bee/Context/Config/IMethodArguments.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -0,0 +1,44 @@
+<?php
+namespace Bee\Context\Config;
+/*
+ * Copyright 2008-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+use Bee_Beans_PropertyValue;
+
+/**
+ * User: mp
+ * Date: 19.08.13
+ * Time: 23:31
+ */
+
+interface IMethodArguments {
+
+ /**
+ * Return the constructor argument values for this bean.
+ * <p>The returned instance can be modified during bean factory post-processing.
+ *
+ * @return Bee_Beans_PropertyValue[]
+ */
+ public function getConstructorArgumentValues();
+
+
+ /**
+ * Enter description here...
+ *
+ * @param Bee_Beans_PropertyValue $arg
+ * @return void
+ */
+ public function addConstructorArgumentValue(Bee_Beans_PropertyValue $arg);
+}
Added: trunk/framework/Bee/Context/Config/MethodArgumentsHolder.php
===================================================================
--- trunk/framework/Bee/Context/Config/MethodArgumentsHolder.php (rev 0)
+++ trunk/framework/Bee/Context/Config/MethodArgumentsHolder.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -0,0 +1,73 @@
+<?php
+namespace Bee\Context\Config;
+/*
+ * Copyright 2008-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+use Bee_Beans_PropertyValue;
+use Bee_Context_Support_BeanUtils;
+
+/**
+ * User: mp
+ * Date: 19.08.13
+ * Time: 23:35
+ */
+
+class MethodArgumentsHolder implements IMethodArguments {
+
+ /**
+ * Enter description here...
+ *
+ * @var Bee_Beans_PropertyValue[]
+ */
+ private $constructorArgumentValues = array();
+
+ /**
+ * Return the constructor argument values for this bean.
+ * <p>The returned instance can be modified during bean factory post-processing.
+ *
+ * @return Bee_Beans_PropertyValue[]
+ */
+ public function getConstructorArgumentValues() {
+ return $this->constructorArgumentValues;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param Bee_Beans_PropertyValue $arg
+ * @return void
+ */
+ public function addConstructorArgumentValue(Bee_Beans_PropertyValue $arg) {
+ $idx = $arg->getName();
+ if(!is_int($idx) || $idx < 0) {
+ trigger_error("Constructor argument index is not an integer or lower than 0 : $idx", E_USER_ERROR);
+ } else {
+ if(array_key_exists($idx, $this->constructorArgumentValues)) {
+ Bee_Context_Support_BeanUtils::mergePropertyValuesIfPossible($this->constructorArgumentValues[$idx], $arg);
+ }
+ $this->constructorArgumentValues[$idx] = $arg;
+ }
+ }
+
+ public function setConstructorArgumentValues(array $args) {
+ $this->constructorArgumentValues = $args;
+ }
+
+ public function addConstructorArgumentValues(array $args) {
+ foreach($args as $arg) {
+ $this->addConstructorArgumentValue($arg);
+ }
+ }
+}
Modified: trunk/framework/Bee/Context/Support/BeanUtils.php
===================================================================
--- trunk/framework/Bee/Context/Support/BeanUtils.php 2013-08-19 12:58:55 UTC (rev 52)
+++ trunk/framework/Bee/Context/Support/BeanUtils.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -24,4 +24,11 @@
}
return $class->newInstanceArgs($args);
}
+
+ public static function mergePropertyValuesIfPossible (Bee_Beans_PropertyValue $parent, Bee_Beans_PropertyValue $child) {
+ $childValue = $child->getValue();
+ if($childValue instanceof Bee_Context_Config_IMergeable && $childValue->getMergeEnabled() && $parent->getValue() instanceof Traversable) {
+ $childValue->merge($parent->getValue());
+ }
+ }
}
Modified: trunk/framework/Bee/Context/Xml/ParserDelegate.php
===================================================================
--- trunk/framework/Bee/Context/Xml/ParserDelegate.php 2013-08-19 12:58:55 UTC (rev 52)
+++ trunk/framework/Bee/Context/Xml/ParserDelegate.php 2013-08-19 22:16:31 UTC (rev 53)
@@ -59,6 +59,8 @@
const PROPERTY_ELEMENT = 'property';
+ const METHOD_INVOCATION_ELEMENT = 'method-invocation';
+
const REF_ELEMENT = 'ref';
const IDREF_ELEMENT = 'idref';
@@ -278,6 +280,7 @@
$this->parseConstructorArgElements($ele, $bd);
$this->parsePropertyElements($ele, $bd);
+ $this->parseMethodInvocationElements($ele, $bd);
// bd.setResource(this.readerContext.getResource());
// bd.setSource(extractSource(ele));
@@ -302,14 +305,14 @@
* Parse constructor-arg sub-elements of the given bean element.
*
* @param DOMElement $beanEle
- * @param Bee_Context_Config_IBeanDefinition $bd
+ * @param Bee\Context\Config\IMethodArguments $argsHolder
* @return void
*/
- public function parseConstructorArgElements(DOMElement $beanEle, Bee_Context_Config_IBeanDefinition $bd) {
+ public function parseConstructorArgElements(DOMElement $beanEle, Bee\Context\Config\IMethodArguments $argsHolder) {
$nl = $beanEle->childNodes;
foreach($nl as $node) {
if ($node instanceof DOMElement && Bee_Utils_Dom::nodeNameEquals($node, self::CONSTRUCTOR_ARG_ELEMENT)) {
- $this->parseConstructorArgElement($node, $bd);
+ $this->parseConstructorArgElement($node, $argsHolder);
}
}
}
@@ -331,24 +334,40 @@
}
}
-
/**
+ * Parse method-invocation sub-elements of the given bean element.
+ *
+ * @param DOMElement $beanEle
+ * @param Bee_Context_Config_IBeanDefinition $bd
+ * @return void
+ */
+ public function parseMethodInvocationElements(DOMElement $beanEle, Bee_Context_Config_IBeanDefinition $bd) {
+ $nl = $beanEle->childNodes;
+ foreach($nl as $node) {
+ if ($node instanceof DOMElement && Bee_Utils_Dom::nodeNameEquals($node, self::METHOD_INVOCATION_ELEMENT)) {
+ $this->parseMethodInvocationElement($node, $bd);
+ }
+ }
+ }
+
+
+ /**
* Parse a constructor-arg element.
*/
- public function parseConstructorArgElement(DOMElement $ele, Bee_Context_Config_IBeanDefinition $bd) {
+ public function parseConstructorArgElement(DOMElement $ele, Bee\Context\Config\IMethodArguments $argsHolder) {
$indexAttr = $ele->getAttribute(self::INDEX_ATTRIBUTE);
if (Bee_Utils_Strings::hasLength($indexAttr) && is_numeric($indexAttr) && ($index = intval($indexAttr)) >= 0) {
- $existingArgs = $bd->getConstructorArgumentValues();
+ $existingArgs = $argsHolder->getConstructorArgumentValues();
if(isset($existingArgs[$index])) {
$this->readerContext->error("Multiple occurrences of value $index for attribute 'index' of tag 'constructor-arg'", $ele);
} else {
try {
array_push($this->parseState, "Constructor_Arg_Idx_$index");
- $value = $this->parsePropertyValue($ele, $bd, null);
+ $value = $this->parsePropertyValue($ele, $argsHolder, null);
$valueHolder = new Bee_Beans_PropertyValue($index, $value);
- $bd->addConstructorArgumentValue($valueHolder);
+ $argsHolder->addConstructorArgumentValue($valueHolder);
array_pop($this->parseState);
} catch (Exception $ex) {
array_pop($this->parseState);
@@ -364,7 +383,7 @@
* Parse a property element.
*/
public function parsePropertyElement(DOMElement $ele, Bee_Context_Config_IBeanDefinition $bd) {
-
+
$propertyName = $ele->getAttribute(self::NAME_ATTRIBUTE);
if (!Bee_Utils_Strings::hasText($propertyName)) {
$this->readerContext->error("Tag 'property' must have a 'name' attribute", $ele);
@@ -388,8 +407,31 @@
}
}
-
/**
+ * Parse a property element.
+ */
+ public function parseMethodInvocationElement(DOMElement $ele, Bee_Context_Config_IBeanDefinition $bd) {
+
+ $methodName = $ele->getAttribute(self::NAME_ATTRIBUTE);
+ if (!Bee_Utils_Strings::hasText($methodName)) {
+ $this->readerContext->error("Tag 'method-invocation' must have a 'name' attribute", $ele);
+ return;
+ }
+ array_push($this->parseState, $methodName);
+ try {
+ $methodInvocation = new \Bee\Beans\MethodInvocation($methodName);
+ $this->parseConstructorArgElements($ele, $methodInvocation);
+ $bd->addMethodInvocation($methodInvocation);
+
+ array_pop($this->parseState);
+ } catch (Exception $ex) {
+ array_pop($this->parseState);
+ throw $ex;
+ }
+ }
+
+
+ /**
* Get the value of a property element. May be a list etc.
* Also used for constructor arguments, "propertyName" being null in this case.
*/
Modified: trunk/framework/bee-beans-1.2.xsd
===================================================================
--- trunk/framework/bee-beans-1.2.xsd 2013-08-19 12:58:55 UTC (rev 52)
+++ trunk/framework/bee-beans-1.2.xsd 2013-08-19 22:16:31 UTC (rev 53)
@@ -138,6 +138,7 @@
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="constructor-arg"/>
<xsd:element ref="property"/>
+ <xsd:element ref="method-invocation"/>
<xsd:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
</xsd:choice>
</xsd:sequence>
@@ -418,6 +419,21 @@
</xsd:annotation>
</xsd:element>
+ <xsd:element name="method-invocation">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ Bean definitions can have zero or more properties.
+ Property elements correspond to JavaBean setter methods exposed
+ by the bean classes. Spring supports primitives, references to other
+ beans in the same or related factories, lists, maps and properties.
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexType>
+ <xsd:choice minOccurs="0" maxOccurs="unbounded">
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+
<xsd:element name="ref">
<xsd:annotation>
<xsd:documentation><![CDATA[
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|