01: // Space4J(TM) - Object Persistence in RAM
02: // Copyright (C) 2003 Sergio Oliveira Junior
03: // This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
04:
05: package org.space4j.demos.phonebook.commands;
06:
07: import org.space4j.*;
08: import org.space4j.demos.phonebook.*;
09: import org.space4j.indexing.*;
10:
11: import java.util.*;
12:
13: public class CreatePhoneCmd extends Command {
14:
15: private Object target;
16: private String name;
17: private String number;
18: private int seq = -1;
19:
20: public CreatePhoneCmd(Object target, String name, String number,
21: int seq) {
22: this .target = target;
23: this .name = name;
24: this .number = number;
25: this .seq = seq;
26: }
27:
28: public int execute(Space space) throws CommandException {
29: Map map = (Map) space.getObject(target);
30: if (map == null)
31: return 0;
32:
33: PhoneBookRecord phone = new PhoneBookRecord(seq);
34: phone.setName(name);
35: phone.setNumber(number);
36: map.put(new Integer(seq), phone);
37:
38: IndexManager im = space.getIndexManager();
39: im.add(phone);
40: return 1;
41: }
42: }
|