1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Appserver\Ldap\DependencyInjection\DeploymentDescriptorParser |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/appserver |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Appserver\Ldap\DependencyInjection; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Psr\Di\ObjectManagerInterface; |
24
|
|
|
use AppserverIo\Ldap\Description\Api\Node\LdapNode; |
25
|
|
|
use AppserverIo\Configuration\Interfaces\NodeInterface; |
26
|
|
|
use AppserverIo\Appserver\DependencyInjectionContainer\AbstractDeploymentDescriptorParser; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Parser to parse a deployment descriptor for beans. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/appserver-io/appserver |
35
|
|
|
* @link http://www.appserver.io |
36
|
|
|
*/ |
37
|
|
|
class DeploymentDescriptorParser extends AbstractDeploymentDescriptorParser |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Parses the bean context's deployment descriptor file for beans |
42
|
|
|
* that has to be registered in the object manager. |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function parse() |
47
|
|
|
{ |
48
|
|
|
|
49
|
|
|
// load the deployment descriptors that has to be parsed |
50
|
|
|
$deploymentDescriptors = $this->loadDeploymentDescriptors(); |
51
|
|
|
|
52
|
|
|
// parse the deployment descriptors from the conf.d and the application's META-INF directory |
53
|
|
|
foreach ($deploymentDescriptors as $deploymentDescriptor) { |
54
|
|
|
// query whether we found epb.xml deployment descriptor file |
55
|
|
|
if (file_exists($deploymentDescriptor) === false) { |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// validate the passed configuration file |
60
|
|
|
/** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */ |
61
|
|
|
$configurationService = $this->getApplication()->newService('AppserverIo\Appserver\Core\Api\ConfigurationService'); |
|
|
|
|
62
|
|
|
$configurationService->validateFile($deploymentDescriptor, null, true); |
63
|
|
|
|
64
|
|
|
// prepare and initialize the configuration node |
65
|
|
|
$ldapNode = new LdapNode(); |
66
|
|
|
$ldapNode->initFromFile($deploymentDescriptor); |
|
|
|
|
67
|
|
|
|
68
|
|
|
// query whether or not the deployment descriptor contains any repositories |
69
|
|
|
if ($repositories = $ldapNode->getRepositories()) { |
70
|
|
|
// parse the repositories from the deployment descriptor |
71
|
|
|
/** @var \AppserverIo\Ldap\Description\Api\Node\RepositoryNode $repositoryNode */ |
72
|
|
|
foreach ($repositories as $repositoryNode) { |
73
|
|
|
$this->processNode($repositoryNode); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// query whether or not the deployment descriptor contains any entities |
78
|
|
|
if ($enties = $ldapNode->getEntities()) { |
79
|
|
|
// parse the entities from the deployment descriptor |
80
|
|
|
/** @var \AppserverIo\Ldap\Description\Api\Node\EntityNode $entityNode */ |
81
|
|
|
foreach ($enties as $entityNode) { |
82
|
|
|
$this->processNode($entityNode); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Creates a new descriptor instance from the data of the passed configuration node |
90
|
|
|
* and add's it to the object manager. |
91
|
|
|
* |
92
|
|
|
* @param \AppserverIo\Configuration\Interfaces\NodeInterface $node The node to process |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
protected function processNode(NodeInterface $node) |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
// load the object manager instance |
100
|
|
|
/** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */ |
101
|
|
|
$objectManager = $this->getApplication()->search(ObjectManagerInterface::IDENTIFIER); |
102
|
|
|
|
103
|
|
|
// iterate over all configured descriptors and try to load object description |
104
|
|
|
/** \AppserverIo\Appserver\Core\Api\Node\DescriptorNode $descriptor */ |
105
|
|
|
foreach ($this->getDescriptors() as $descriptor) { |
106
|
|
|
try { |
107
|
|
|
// load the descriptor class |
108
|
|
|
$descriptorClass = $descriptor->getNodeValue()->getValue(); |
109
|
|
|
|
110
|
|
|
// load the object descriptor, initialize the servlet mappings and add it to the object manager |
111
|
|
|
/** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */ |
112
|
|
|
if ($objectDescriptor = $descriptorClass::newDescriptorInstance()->fromConfiguration($node)) { |
113
|
|
|
$objectManager->addObjectDescriptor($objectDescriptor, true); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// proceed with the next descriptor |
117
|
|
|
continue; |
118
|
|
|
|
119
|
|
|
// if class can not be reflected continue with next class |
120
|
|
|
} catch (\Exception $e) { |
121
|
|
|
// log an error message |
122
|
|
|
$this->getApplication()->getInitialContext()->getSystemLogger()->error($e->__toString()); |
|
|
|
|
123
|
|
|
|
124
|
|
|
// proceed with the next descriptor |
125
|
|
|
continue; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|