ffead.server.doc
AppContext.cpp
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * AppContext.cpp
18  *
19  * Created on: Mar 30, 2010
20  * Author: sumeet
21  */
22 
23 #include "AppContext.h"
24 
25 BeanException::BeanException(string message)
26 {
27  this->setMessage(message);
28 }
29 
30 BeanException::~BeanException() throw()
31 {
32 
33 }
34 
35 AppContext* AppContext::_instance = NULL;
36 
37 void AppContext::init()
38 {
39  if(_instance==NULL)
40  {
41  _instance = new AppContext();
42  }
43 }
44 
45 AppContext::AppContext() {
46  // TODO Auto-generated constructor stub
47 
48 }
49 
50 AppContext::~AppContext() {
51  // TODO Auto-generated destructor stub
52 }
53 
54 bool AppContext::registerComponent(string name)
55 {
56  init();
57  if(_instance->components.find(name)!=_instance->components.end())
58  {
59  return false;
60  }
61  else
62  {
63  _instance->components[name] = "";
64  return true;
65  }
66 }
67 
68 bool AppContext::unregisterComponent(string name)
69 {
70  init();
71  map<string,string>::iterator it = _instance->components.find(name);
72  if(it!=_instance->components.end())
73  {
74  _instance->components.erase(it);
75  return true;
76  }
77  else
78  return false;
79 }
80 
81 void AppContext::lookup(string name)
82 {
83  if(_instance==NULL)
84  throw new Exception("Bean Container Not Running");
85  if(_instance->components.find(name)==_instance->components.end())
86  {
87  throw new BeanException("Bean Not Deployed");
88  }
89 }