01: /*
02: $Header: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/editor/LookupAction.java,v 1.4 2002/04/26 22:01:05 wbiggs Exp $
03:
04: This file is part of XORM.
05:
06: XORM is free software; you can redistribute it and/or modify
07: it under the terms of the GNU General Public License as published by
08: the Free Software Foundation; either version 2 of the License, or
09: (at your option) any later version.
10:
11: XORM is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with Foobar; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package org.xorm.tools.editor;
21:
22: import org.xorm.XORM;
23: import java.io.*;
24: import javax.jdo.*;
25:
26: public class LookupAction extends Action {
27: public LookupAction(PersistenceManager mgr) {
28: super (mgr);
29: }
30:
31: public Object go() {
32: System.out.println("LOOKUP OBJECT");
33:
34: Class clazz = null;
35: do {
36: System.out.print("Enter Interface Class: ");
37: clazz = readClass();
38: } while (clazz == null);
39:
40: System.out.print("Enter Object ID: ");
41: String objectId = readLine();
42:
43: // TODO don't assume it's an Integer or String
44: Object idObj = objectId;
45: try {
46: idObj = new Integer(objectId);
47: } catch (NumberFormatException e) {
48: // ignore, leave it as a Stringn
49: }
50:
51: Object obj = mgr.getObjectById(XORM.newObjectId(clazz, idObj),
52: false);
53: if (obj == null) {
54: System.out.println("Object with that ID not found.");
55: return null;
56: }
57: EditAction action = new EditAction(mgr, obj);
58: action.go();
59: return obj;
60: }
61: }
|