/**
* This method merges the installation steps of the passed provisioning node into the steps of
* this instance. If a installation node with the same type already exists, the one of this
* instance will be overwritten.
*
* @param \AppserverIo\Appserver\Core\Api\Node\ContextNode $contextNode The node with the installation steps we want to merge
*
* @return void
*/
public function merge(ContextNode $contextNode)
{
// merge the application type
if ($type = $contextNode->getType()) {
$this->setType($type);
}
// merge the application factory class name
if ($factory = $contextNode->getFactory()) {
$this->setFactory($factory);
}
// merge the application webapp path
if ($webappPath = $contextNode->getWebappPath()) {
$this->setWebappPath($webappPath);
}
// load the params defined in this context
$localParams = $this->getParams();
// merge them with the passed ones
foreach ($contextNode->getParams() as $paramToMerge) {
$isMerged = false;
/** @var \AppserverIo\Appserver\Core\Api\Node\ParamNode $param */
foreach ($localParams as $key => $param) {
if ($param->getName() == $paramToMerge->getName()) {
$localParams[$key] = $paramToMerge;
$isMerged = true;
}
}
if ($isMerged === false) {
$localParams[$paramToMerge->getUuid()] = $paramToMerge;
}
}
// set the params back to the context
$this->setParams($localParams);
// load the managers defined of this context
$localManagers = $this->getManagers();
// merge them with the passed ones
/** @var \AppserverIo\Appserver\Core\Api\Node\ManagerNode $managerToMerge */
foreach ($contextNode->getManagers() as $managerToMerge) {
$isMerged = false;
/** @var \AppserverIo\Appserver\Core\Api\Node\ManagerNode $manager */
foreach ($localManagers as $key => $manager) {
if ($manager->getName() === $managerToMerge->getName()) {
$manager->merge($managerToMerge);
$localManagers[$key] = $manager;
$isMerged = true;
}
}
if ($isMerged === false) {
$localManagers[$managerToMerge->getUuid()] = $managerToMerge;
}
}
// set the managers back to the context
$this->setManagers($localManagers);
// load the class loaders of this context
$localClassLoaders = $this->getClassLoaders();
// merge them with the passed ones
/** @var \AppserverIo\Appserver\Core\Api\Node\ClassLoaderNode $classLoaderToMerge */
foreach ($contextNode->getClassLoaders() as $classLoaderToMerge) {
$isMerged = false;
/** @var \AppserverIo\Appserver\Core\Api\Node\ClassLoaderNode $classLoader */
foreach ($localClassLoaders as $key => $classLoader) {
if ($classLoader->getName() === $classLoaderToMerge->getName()) {
$localClassLoaders[$key] = $classLoaderToMerge;
$isMerged = true;
}
}
if ($isMerged === false) {
$localClassLoaders[$classLoaderToMerge->getUuid()] = $classLoaderToMerge;
}
}
// set the class loaders back to the context
$this->setClassLoaders($localClassLoaders);
// load the loggers of this context
$localLoggers = $this->getLoggers();
// merge them with the passed ones (DO override already registered loggers)
/** @var \AppserverIo\Appserver\Core\Api\Node\LoggerNode $loggerToMerge */
foreach ($contextNode->getLoggers() as $loggerToMerge) {
$localLoggers[$loggerToMerge->getName()] = $loggerToMerge;
}
// set the loggers back to the context
$this->setLoggers($localLoggers);
}