01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: SubmissionModel.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.gui.model;
09:
10: import com.uwyn.rife.gui.model.exceptions.GuiModelException;
11: import com.uwyn.rife.gui.model.exceptions.ParticlePropertyInvalidRemovalException;
12: import java.util.Collection;
13:
14: public class SubmissionModel extends ParticleModel {
15: private SubmissionIdModel mSubmissionIdModel = null;
16:
17: SubmissionModel(ElementModel element, String id)
18: throws GuiModelException {
19: super ();
20:
21: assert element != null;
22: assert id != null;
23: assert id.length() > 0;
24:
25: try {
26: mSubmissionIdModel = new SubmissionIdModel(this , id);
27: } catch (GuiModelException e) {
28: e.fillInStackTrace();
29: throw e;
30: }
31:
32: element.addChild(this );
33: }
34:
35: protected ParticleModel findConflictingParticle(
36: ParticleModel parentParticle) {
37: assert parentParticle != null;
38:
39: for (SubmissionModel sibling : parentParticle
40: .getChildren(SubmissionModel.class)) {
41: if (sibling.getId().getName().equals(getId().getName())) {
42: return sibling;
43: }
44: }
45:
46: return null;
47: }
48:
49: public boolean removeProperty(ParticlePropertyModel property)
50: throws GuiModelException {
51: if (null == property)
52: throw new IllegalArgumentException(
53: "property can't be null.");
54:
55: if (property instanceof SubmissionIdModel) {
56: throw new ParticlePropertyInvalidRemovalException(this ,
57: property);
58: } else {
59: return super .removeProperty(property);
60: }
61: }
62:
63: public SubmissionIdModel getId() {
64: return mSubmissionIdModel;
65: }
66:
67: public SubmissionParameterModel addParameter(String name)
68: throws GuiModelException {
69: if (null == name)
70: throw new IllegalArgumentException("name can't be null.");
71: if (0 == name.length())
72: throw new IllegalArgumentException("name can't be empty.");
73:
74: return new SubmissionParameterModel(this , name);
75: }
76:
77: public Collection<SubmissionParameterModel> getParameters() {
78: return getProperties(SubmissionParameterModel.class);
79: }
80:
81: public int countParameters() {
82: return countProperties(SubmissionParameterModel.class);
83: }
84: }
|