1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#ifndef ICE_PACK_COMPONENT_BUILDER_H
#define ICE_PACK_COMPONENT_BUILDER_H
#include <IceUtil/Shared.h>
#include <IcePack/Admin.h>
#include <Yellow/Yellow.h>
#include <xercesc/sax/HandlerBase.hpp>
#include <map>
#include <vector>
#include <stack>
namespace IcePack
{
//
// A deployment task. A deployment task is executed when a component
// is deployed and it's undo when the component is removed.
//
class Task : public ::IceUtil::SimpleShared
{
public:
virtual void execute() = 0;
virtual void undo() = 0;
};
typedef ::IceUtil::Handle< ::IcePack::Task> TaskPtr;
class ComponentBuilder;
class DeploySAXParseException : public SAXParseException
{
public:
DeploySAXParseException(const std::string&, const Locator* locator);
};
//
// A wrapper for ParserDeploymentException.
//
class ParserDeploymentWrapperException : public SAXException
{
public:
ParserDeploymentWrapperException(const ParserDeploymentException&);
void throwParserDeploymentException() const;
private:
ParserDeploymentException _exception;
};
//
// SAX error handler for compoonent descriptors.
//
class ComponentErrorHandler : public ErrorHandler
{
public:
ComponentErrorHandler(ComponentBuilder&);
void warning(const SAXParseException& exception);
void error(const SAXParseException& exception);
void fatalError(const SAXParseException& exception);
void resetErrors();
private:
ComponentBuilder& _builder;
};
//
// SAX parser handler for component descriptors.
//
class ComponentHandler : public DocumentHandler
{
public:
ComponentHandler(ComponentBuilder&);
virtual void characters(const XMLCh*const, const unsigned int);
virtual void startElement(const XMLCh*const, AttributeList&);
virtual void endElement(const XMLCh*const);
virtual void setDocumentLocator(const Locator *const);
virtual void ignorableWhitespace(const XMLCh*const, const unsigned int);
virtual void processingInstruction(const XMLCh*const, const XMLCh*const);
virtual void resetDocument();
virtual void startDocument();
virtual void endDocument();
protected:
std::string getAttributeValue(const AttributeList&, const std::string&) const;
std::string getAttributeValueWithDefault(const AttributeList&, const std::string&, const std::string&) const;
std::string toString(const XMLCh*const) const;
std::string elementValue() const;
bool isCurrentTargetDeployable() const;
ComponentBuilder& _builder;
std::stack<std::string> _elements;
std::string _currentAdapterId;
std::string _currentTarget;
bool _isCurrentTargetDeployable;
const Locator* _locator;
};
//
// The component builder builds and execute the tasks that need to be
// executed to deploy a component described in a component
// descriptor. There's two phase to deploy or remove a component:
//
// * descriptor parsing: the builder parse() method initiate the
// parsing. The parser will call the builder methods to setup the
// deployment tasks. Once the parsing is finished all the deployment
// tasks should be ready to be executed or undo
//
// * execution of the tasks to deploy the component or undo'ing of the
// tasks to remove the component.
//
class ComponentBuilder : public Task
{
public:
ComponentBuilder(const Ice::CommunicatorPtr&,
const std::map<std::string, std::string>&,
const std::vector<std::string>&);
virtual void execute();
virtual void undo();
void parse(const std::string&, ComponentHandler&);
void setDocumentLocator(const Locator*const locator);
void setYellowAdmin(const Yellow::AdminPrx&);
bool isTargetDeployable(const std::string&) const;
void createDirectory(const std::string&, bool = false);
void createConfigFile(const std::string&);
void addProperty(const std::string&, const std::string&);
void addOffer(const std::string&, const std::string&, const std::string&);
void overrideBaseDir(const std::string&);
virtual std::string getDefaultAdapterId(const std::string&);
std::string toLocation(const std::string&) const;
std::string substitute(const std::string&) const;
std::vector<std::string> toTargets(const std::string&) const;
void undoFrom(std::vector<TaskPtr>::iterator);
protected:
Ice::CommunicatorPtr _communicator;
Yellow::AdminPrx _yellowAdmin;
Ice::PropertiesPtr _properties;
std::map<std::string, std::string> _variables;
std::vector<TaskPtr> _tasks;
std::string _configFile;
std::vector<std::string> _targets;
const Locator* _locator;
};
}
#endif
|