View Javadoc

1   /*
2    Wotonomy: OpenStep design patterns for pure Java applications.
3    Copyright (C) 2001 Michael Powers
4   
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9   
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14  
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, see http://www.gnu.org
17   */
18  
19  package net.wotonomy.access;
20  
21  import net.wotonomy.foundation.NSArray;
22  import net.wotonomy.foundation.NSDictionary;
23  import net.wotonomy.foundation.NSMutableArray;
24  import net.wotonomy.foundation.NSMutableDictionary;
25  /***
26  * Represents a stored procedure in a database.
27  *
28  * @author ezamudio@nasoft.com
29  * @author $Author: cgruber $
30  * @version $Revision: 894 $
31  */
32  public class EOStoredProcedure implements EOPropertyListEncoding {
33  
34  	protected String _name;
35  	protected String _externalName;
36  	protected EOModel _model;
37  	protected NSArray _arguments = NSArray.EmptyArray;
38  	protected NSDictionary _userInfo = NSDictionary.EmptyDictionary;
39  	protected NSDictionary _internalInfo = NSDictionary.EmptyDictionary;
40  
41  	/*** Creates a stored procedure from a property list. */
42  	public EOStoredProcedure(NSDictionary dict, Object obj) {
43  		super();
44  		if (obj instanceof EOModel)
45  			_model = (EOModel)obj;
46  		NSArray a = (NSArray)dict.objectForKey("arguments");
47  		if (a != null) {
48  			NSMutableArray args = new NSMutableArray(a.count());
49  			for (int i = 0; i < a.count(); i++) {
50  				NSDictionary ad = (NSDictionary)a.objectAtIndex(i);
51  				EOAttribute arg = new EOAttribute(ad, this);
52  				args.addObject(arg);
53  			}
54  			_arguments = args;
55  		}
56  		setName((String)dict.objectForKey("name"));
57  		setExternalName((String)dict.objectForKey("externalName"));
58  		if (dict.objectForKey("userInfo") != null)
59  			setUserInfo((NSDictionary)dict.objectForKey("userInfo"));
60  		if (dict.objectForKey("internalInfo") != null)
61  			_internalInfo = (NSDictionary)dict.objectForKey("internalInfo");
62  	}
63  
64  	public EOStoredProcedure(String withName) {
65  		super();
66  		setName(withName);
67  	}
68  
69  	public void setName(String value) {
70  		_name = value;
71  	}
72  	public String name() {
73  		return _name;
74  	}
75  
76  	public void setExternalName(String value) {
77  		_externalName = value;
78  	}
79  	public String externalName() {
80  		return _externalName;
81  	}
82  
83  	public void setArguments(NSArray value) {
84  		_arguments = value;
85  	}
86  	public NSArray arguments() {
87  		return _arguments;
88  	}
89  
90  	public EOModel model() {
91  		return _model;
92  	}
93  
94  	public void setUserInfo(NSDictionary info) {
95  		_userInfo = info;
96  	}
97  	public NSDictionary userInfo() {
98  		return _userInfo;
99  	}
100 
101 	public void awakeWithPropertyList(NSDictionary plist) {
102 	}
103 
104 	public void encodeIntoPropertyList(NSMutableDictionary plist) {
105 		plist.setObjectForKey(name(), "name");
106 		plist.setObjectForKey(externalName(), "externalName");
107 		NSMutableArray arr = new NSMutableArray(_arguments.count());
108 		NSMutableDictionary d = null;
109 		for (int i = 0; i < _arguments.count(); i++) {
110 			EOAttribute a = (EOAttribute)_arguments.objectAtIndex(i);
111 			d = new NSMutableDictionary();
112 			a.encodeIntoPropertyList(d);
113 			arr.addObject(d);
114 		}
115 		plist.setObjectForKey(arr, "arguments");
116 	}
117 
118 }
119 /*
120  * $Log$
121  * Revision 1.2  2006/02/16 16:47:14  cgruber
122  * Move some classes in to "internal" packages and re-work imports, etc.
123  *
124  * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
125  *
126  * Revision 1.1  2006/02/16 13:19:57  cgruber
127  * Check in all sources in eclipse-friendly maven-enabled packages.
128  *
129  * Revision 1.4  2003/08/11 19:38:27  chochos
130  * Can now read from a file and re-write to another file.
131  *
132  * Revision 1.3  2003/08/09 01:36:32  chochos
133  * implement EOPropertyListEncoding
134  *
135  * Revision 1.2  2003/08/08 02:14:43  chochos
136  * can create a stored procedure from a property list. main accessors are in place.
137  *
138  * Revision 1.1  2003/08/07 02:41:04  chochos
139  * these don't do much for now.
140  *
141 */