Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDARepositoryManager/addConnection.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % ADDCONNECTION adds a new managed connection to the repository manager. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % description: addconnection adds a new managed connection to the | |
5 % repository manager. | |
6 % this method still adds a new connection. it doesn't open by | |
7 % default the connection and for this reason it is not | |
8 % necessary to define a password yet. | |
9 % | |
10 % call: conn = rm.addconnection(pl); | |
11 % conn = rm.addconnection('hostname'); | |
12 % conn = rm.addconnection('hostname', 'database'); | |
13 % conn = rm.addconnection('hostname', 'database', 'username'); | |
14 % conn = rm.addconnection('hostname', 'database', 'username', 'password'); | |
15 % | |
16 % <a href="matlab:web(ltpdarepositorymanager.getinfo('addconnection').tohtml, '-helpbrowser')">parameter sets</a> | |
17 % | |
18 % version: $Id: addConnection.m,v 1.6 2011/03/28 12:45:44 hewitson Exp $ | |
19 % | |
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
21 | |
22 function varargout = addConnection(varargin) | |
23 | |
24 % check if this is a call for parameters | |
25 if utils.helper.isinfocall(varargin{:}) | |
26 varargout{1} = getinfo(varargin{3}); | |
27 return | |
28 end | |
29 | |
30 import utils.const.* | |
31 utils.helper.msg(utils.const.msg.MNAME , 'running %s/%s', mfilename('class'), mfilename); | |
32 | |
33 % get the repository manager - there should only be one! | |
34 [rm, invars, rest] = utils.helper.collect_objects(varargin(:), 'LTPDARepositoryManager'); | |
35 | |
36 % collect all plists | |
37 [pl, invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
38 | |
39 pl = combine(pl, getdefaultplist); | |
40 hostname = pl.find('hostname'); | |
41 database = pl.find('database'); | |
42 username = pl.find('username'); | |
43 password = pl.find('password'); | |
44 autoconnect = pl.find('connect'); | |
45 | |
46 % check through 'rest' | |
47 if numel(rest) > 0 | |
48 hostname = rest{1}; | |
49 end | |
50 if numel(rest) > 1 | |
51 database = rest{2}; | |
52 end | |
53 if numel(rest) > 2 | |
54 username = rest{3}; | |
55 end | |
56 if numel(rest) > 3 | |
57 password = rest{4}; | |
58 end | |
59 | |
60 conn = mpipeline.repository.RepositoryConnection([]); | |
61 conn.setHostname(hostname); | |
62 conn.setDatabase(database); | |
63 conn.setUsername(username); | |
64 conn.setPassword(password); | |
65 | |
66 if ~isempty(password) && autoconnect | |
67 conn.openconnection(); | |
68 end | |
69 | |
70 rm.manager.addConnection(conn); | |
71 if ~isempty(rm.gui) | |
72 rm.gui.reloadConnectionTable(); | |
73 end | |
74 | |
75 if nargout == 1 | |
76 varargout{1} = conn; | |
77 end | |
78 | |
79 end | |
80 | |
81 %-------------------------------------------------------------------------- | |
82 % get info object | |
83 %-------------------------------------------------------------------------- | |
84 function ii = getinfo(varargin) | |
85 if nargin == 1 && strcmpi(varargin{1}, 'none') | |
86 sets = {}; | |
87 pl = []; | |
88 else | |
89 sets = {'default'}; | |
90 pl = getdefaultplist; | |
91 end | |
92 % build info object | |
93 ii = minfo(mfilename, 'LTPDARepositoryManager', 'ltpda', utils.const.categories.gui, '$id: psd.m,v 1.53 2009/12/17 08:04:43 mauro exp $', sets, pl); | |
94 end | |
95 | |
96 %-------------------------------------------------------------------------- | |
97 % get default plist | |
98 %-------------------------------------------------------------------------- | |
99 function pl = getdefaultplist() | |
100 | |
101 % initialise plist | |
102 pl = plist(); | |
103 | |
104 % hostname | |
105 p = param({'hostname', 'the hostname of the repository to connect to.'}, paramValue.EMPTY_STRING); | |
106 pl.append(p); | |
107 | |
108 % database | |
109 p = param({'database', 'the database on the repository.'}, paramValue.EMPTY_STRING); | |
110 pl.append(p); | |
111 | |
112 % username | |
113 p = param({'username', 'the username to connect with.'}, paramValue.EMPTY_STRING); | |
114 pl.append(p); | |
115 | |
116 % password | |
117 p = param({'password', 'the password to connect with. leave this empty to be prompted on connection.'}, paramValue.EMPTY_STRING); | |
118 pl.append(p); | |
119 | |
120 % auto connect | |
121 p = param({'connect', '''true'' or ''false'' if the repository manager should open the connection.'}, paramValue.FALSE_TRUE); | |
122 pl.append(p); | |
123 | |
124 end | |
125 |