Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDARepositoryManager/newConnection.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 % NEWCONNECTION makes a new managed repository connection. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: NEWCONNECTION makes a new managed repository connection. | |
5 % | |
6 % CALL: conn = rm.newConnection(pl); | |
7 % conn = rm.newConnection('hostname'); | |
8 % conn = rm.newConnection('hostname', 'database'); | |
9 % conn = rm.newConnection('hostname', 'database', 'username'); | |
10 % conn = rm.newConnection('hostname', 'database', 'username', 'password'); | |
11 % | |
12 % If all required connection fields are input, the connection will be | |
13 % silently created and added to the manager. Otherwise, a connection dialog | |
14 % will be presented and the resulting connection added to the manager. | |
15 % | |
16 % <a href="matlab:web(LTPDARepositoryManager.getInfo('newConnection').tohtml, '-helpbrowser')">Parameters Description</a> | |
17 % | |
18 % VERSION: $Id: newConnection.m,v 1.10 2011/04/08 08:56:35 hewitson Exp $ | |
19 % | |
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
21 | |
22 function varargout = newConnection(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(msg.PROC3, '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 | |
45 % Check through 'rest' | |
46 if numel(rest) > 0 | |
47 hostname = rest{1}; | |
48 end | |
49 if numel(rest) > 1 | |
50 database = rest{2}; | |
51 end | |
52 if numel(rest) > 2 | |
53 username = rest{3}; | |
54 end | |
55 if numel(rest) > 3 | |
56 password = rest{4}; | |
57 end | |
58 | |
59 conn = rm.manager.findExactConnection(hostname, database, username); | |
60 | |
61 if ~isempty(conn) | |
62 if ~isempty(password) && isempty(char(conn.getPassword)) | |
63 conn.setPassword(password); | |
64 end | |
65 else | |
66 conn = rm.basic_newConnection(hostname, database, username, password); | |
67 end | |
68 | |
69 % my be it is necessary to update the GUI table | |
70 if ~isempty(rm.gui) | |
71 rm.gui.reloadConnectionTable(); | |
72 end | |
73 if ~isempty(rm.selector) | |
74 rm.selector.reloadConnectionTable(); | |
75 end | |
76 varargout{1} = conn; | |
77 | |
78 end | |
79 | |
80 %-------------------------------------------------------------------------- | |
81 % Get Info Object | |
82 %-------------------------------------------------------------------------- | |
83 function ii = getInfo(varargin) | |
84 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
85 sets = {}; | |
86 pl = []; | |
87 else | |
88 sets = {'Default'}; | |
89 pl = getDefaultPlist; | |
90 end | |
91 % Build info object | |
92 ii = minfo(mfilename, 'LTPDARepositoryManager', 'ltpda', utils.const.categories.gui, '$Id: newConnection.m,v 1.10 2011/04/08 08:56:35 hewitson Exp $', sets, pl); | |
93 end | |
94 | |
95 %-------------------------------------------------------------------------- | |
96 % Get Default Plist | |
97 %-------------------------------------------------------------------------- | |
98 function pl = getDefaultPlist() | |
99 | |
100 % Initialise plist | |
101 pl = plist(); | |
102 | |
103 % hostname | |
104 p = param({'hostname', 'The hostname of the repository to connect to.'}, paramValue.EMPTY_STRING); | |
105 pl.append(p); | |
106 | |
107 % database | |
108 p = param({'database', 'The database on the repository.'}, paramValue.EMPTY_STRING); | |
109 pl.append(p); | |
110 | |
111 % username | |
112 p = param({'username', 'The username to connect with.'}, paramValue.EMPTY_STRING); | |
113 pl.append(p); | |
114 | |
115 % password | |
116 p = param({'password', 'The password to connect with. Leave this empty to be prompted on connection.'}, paramValue.EMPTY_STRING); | |
117 pl.append(p); | |
118 | |
119 end | |
120 |