summaryrefslogtreecommitdiff
path: root/ACEXML/compass/AssemblyFactory.cpp
blob: 5a4f3b1afd41d37d85d372fb3f47c4700b5cb19e (plain)
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
// $Id$

#include "AssemblyFactory.h"
#include "ACEXML/common/StreamFactory.h"

using namespace Deployment;

AssemblyFactory::AssemblyFactory()
  : cookies_()
{}

AssemblyFactory::~AssemblyFactory()
{}


Cookie
AssemblyFactory::create (const Location& assembly_loc)
  ACE_THROW_SPEC ((InvalidLocation, CreateFailure))
{
  ACEXML_StreamFactory factory;
  ACEXML_CharStream* stream = factory.create_stream (assembly_loc.c_str());
  if (stream == 0)
    ACE_THROW (InvalidLocation());
  char buf[10];
  int size = ACE_OS::sprintf (buf, "%@", stream);
  buf[size] = 0;
  ACEXML_String cookie (buf);
  Assembly* assembly = 0;
  ACE_NEW (assembly, Assembly (AssemblyState::INACTIVE, stream));
  if (assembly == 0)
    ACE_THROW ((CreateFailure()));
  if (this->cookies_.bind (ret, assembly) != 0)
    ACE_THROW ((CreateFailure()));
  return cookie;
}

Assembly*
AssemblyFactory::lookup (const Cookie& c)
  ACE_THROW_SPEC ((InvalidAssembly))
{
  Assembly* asm = 0;
  if (this->cookies_->find (c, asm) != 0)
    ACE_THROW (InvalidAssembly());
  return asm;
}

void
AssemblyFactory::destroy (const Cookie& c)
  ACE_THROW_SPEC ((InvalidAssembly, RemoveFailure))
{
  Assembly* asm = 0;
  if (this->cookies_->unbind (c, asm) != 0)
    ACE_THROW (InvalidAssembly());
  delete asm;
}