// ********************************************************************** // // Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** #ifndef ICE_GRID_DESCRIPTOR_HELPER_H #define ICE_GRID_DESCRIPTOR_HELPER_H #include #include namespace IceGrid { class DescriptorVariables : public IceUtil::SimpleShared { public: DescriptorVariables(); DescriptorVariables(const std::map&); std::string substitute(const std::string&); std::string substituteWithMissing(const std::string&, std::set&); std::string getVariable(const std::string&); void addVariable(const std::string&, const std::string&); bool hasVariable(const std::string&) const; void remove(const std::string&); void dumpVariables() const; void reset(const std::map&, const std::vector&); void push(const std::map&); void push(); void pop(); std::map getCurrentScopeVariables() const; std::vector getCurrentScopeParameters() const; void addParameter(const std::string&); std::vector getDeploymentTargets(const std::string&) const; void substitution(bool); bool substitution() const; private: std::string substituteImpl(const std::string&, std::set&); struct VariableScope { std::map variables; std::set used; std::set parameters; bool substitution; }; std::vector _scopes; std::vector _deploymentTargets; }; typedef IceUtil::Handle DescriptorVariablesPtr; class DescriptorHelper; class ServerDescriptorHelper; class ServiceDescriptorHelper; class DescriptorTemplates : public IceUtil::SimpleShared { public: DescriptorTemplates(const ApplicationDescriptorPtr&); void setDescriptor(const ApplicationDescriptorPtr&); ServerDescriptorPtr instantiateServer(const DescriptorHelper&, const std::string&, const std::map&); ServiceDescriptorPtr instantiateService(const DescriptorHelper&, const std::string&, const std::map&); void addServerTemplate(const std::string&, const ServerDescriptorPtr&, const Ice::StringSeq&); void addServiceTemplate(const std::string&, const ServiceDescriptorPtr&, const Ice::StringSeq&); ApplicationDescriptorPtr getApplicationDescriptor() const; private: ApplicationDescriptorPtr _application; }; typedef IceUtil::Handle DescriptorTemplatesPtr; class XmlAttributesHelper { public: XmlAttributesHelper(const DescriptorVariablesPtr&, const IceXML::Attributes&); bool contains(const std::string&); std::string operator()(const std::string&); std::string operator()(const std::string&, const std::string&); private: const DescriptorVariablesPtr& _variables; const IceXML::Attributes& _attributes; }; class DescriptorHelper { public: const DescriptorVariablesPtr& getVariables() const; protected: DescriptorHelper(const Ice::CommunicatorPtr&, const DescriptorVariablesPtr&, const DescriptorTemplatesPtr&); DescriptorHelper(const DescriptorHelper&); virtual ~DescriptorHelper(); const Ice::CommunicatorPtr _communicator; const DescriptorVariablesPtr _variables; const DescriptorTemplatesPtr _templates; }; class ServerDescriptorHelper; class ServiceDescriptorHelper; class ApplicationDescriptorHelper : public DescriptorHelper { public: ApplicationDescriptorHelper(const Ice::CommunicatorPtr&, const ApplicationDescriptorPtr&); ApplicationDescriptorHelper(const Ice::CommunicatorPtr&, const DescriptorVariablesPtr&, const IceXML::Attributes&); void endParsing(); const ApplicationDescriptorPtr& getDescriptor() const; void setComment(const std::string&); void addNode(const IceXML::Attributes&); void endNodeParsing(); void addServer(const std::string&, const IceXML::Attributes&); void addServer(const ServerDescriptorPtr&); std::auto_ptr addServerTemplate(const std::string&, const IceXML::Attributes&); std::auto_ptr addServiceTemplate(const std::string&, const IceXML::Attributes&); void update(const ApplicationUpdateDescriptor&); void addServerInstance(const std::string&, const std::map&); void instantiate(); private: void pushNodeVariables(const std::string&); ApplicationDescriptorPtr _descriptor; }; class ComponentDescriptorHelper : public DescriptorHelper { public: ComponentDescriptorHelper(const DescriptorHelper&); ComponentDescriptorHelper(const Ice::CommunicatorPtr&, const DescriptorVariablesPtr&, const DescriptorTemplatesPtr&); bool operator==(const ComponentDescriptorHelper&) const; bool operator!=(const ComponentDescriptorHelper&) const; void setComment(const std::string&); void addProperty(const IceXML::Attributes&); void addAdapter(const IceXML::Attributes&); void addObject(const IceXML::Attributes&); void addDbEnv(const IceXML::Attributes&); void addDbEnvProperty(const IceXML::Attributes&); protected: void init(const ComponentDescriptorPtr&, const IceXML::Attributes& = IceXML::Attributes()); virtual void instantiateImpl(const ComponentDescriptorPtr&, std::set&) const; private: ComponentDescriptorPtr _descriptor; }; class ServerDescriptorHelper : public ComponentDescriptorHelper { public: ServerDescriptorHelper(const DescriptorHelper&, const ServerDescriptorPtr&); ServerDescriptorHelper(const DescriptorHelper&, const IceXML::Attributes&, const std::string&); ~ServerDescriptorHelper(); void endParsing(); bool operator==(const ServerDescriptorHelper&) const; bool operator!=(const ServerDescriptorHelper&) const; virtual ServerDescriptorPtr instantiate(std::set&) const; const ServerDescriptorPtr& getDescriptor() const; const std::string& getTemplateId() const; void addService(const std::string&, const IceXML::Attributes&); void addService(const ServiceDescriptorPtr&); std::auto_ptr addServiceTemplate(const std::string&, const IceXML::Attributes&); void addOption(const std::string&); void addEnv(const std::string&); void addInterpreterOption(const std::string&); private: virtual void instantiateImpl(const ServerDescriptorPtr&, std::set&) const; ServerDescriptorPtr _descriptor; std::string _templateId; }; class ServiceDescriptorHelper : public ComponentDescriptorHelper { public: ServiceDescriptorHelper(const DescriptorHelper&, const ServiceDescriptorPtr&); ServiceDescriptorHelper(const DescriptorHelper&, const IceXML::Attributes&, const std::string&); ~ServiceDescriptorHelper(); void endParsing(); bool operator==(const ServiceDescriptorHelper&) const; bool operator!=(const ServiceDescriptorHelper&) const; virtual ServiceDescriptorPtr instantiate(std::set&) const; const ServiceDescriptorPtr& getDescriptor() const; const std::string& getTemplateId() const; private: virtual void instantiateImpl(const ServiceDescriptorPtr&, std::set&) const; ServiceDescriptorPtr _descriptor; std::string _templateId; }; } #endif