summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Direct.cpp
blob: d97a903c3710b04c77912c5fb0342c6b5e2ba98a (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
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
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#include <Ice/Direct.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/ServantLocator.h>
#include <Ice/Reference.h>
#include <Ice/Object.h>
#include <Ice/LocalException.h>

using namespace std;
using namespace Ice;
using namespace IceInternal;

IceInternal::Direct::Direct(const ObjectAdapterPtr& adapter, const Current& current) :
    _adapter(adapter),
    _current(current)
{
    try
    {
	_servant = _adapter->identityToServant(_current.id);
    
	if(!_servant && !_current.id.category.empty())
	{
	    _locator = _adapter->findServantLocator(_current.id.category);
	    if(_locator)
	    {
		_servant = _locator->locate(_adapter, _current, _cookie);
	    }
	}

	if(!_servant)
	{
	    _locator = _adapter->findServantLocator("");
	    if(_locator)
	    {
		_servant = _locator->locate(_adapter, _current, _cookie);
	    }
	}
	
	if(_servant && !_current.facet.empty())
	{
	    _facetServant = _servant->ice_findFacet(_current.facet);
	    if(!_facetServant)
	    {
		FacetNotExistException ex(__FILE__, __LINE__);
		ex.facet = _current.facet;
		throw ex;
	    }
	}
    }
    catch(...)
    {
	if(_locator && _servant)
	{
	    _locator->finished(_adapter, _current, _servant, _cookie);
	}
	throw;
    }

    if(!_servant)
    {
	ObjectNotExistException ex(__FILE__, __LINE__);
	ex.id = _current.id;
	throw ex;
    }
}

IceInternal::Direct::~Direct()
{
    if(_locator && _servant)
    {
	_locator->finished(_adapter, _current, _servant, _cookie);
    }
}

const ObjectPtr&
IceInternal::Direct::facetServant()
{
    if(_facetServant)
    {
	return _facetServant;
    }
    else
    {
	return _servant;
    }
}