01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10: * for the specific language governing rights and limitations under the
11: * License.
12: *
13: * The Original Code is Riot.
14: *
15: * The Initial Developer of the Original Code is
16: * Neteye GmbH.
17: * Portions created by the Initial Developer are Copyright (C) 2006
18: * the Initial Developer. All Rights Reserved.
19: *
20: * Contributor(s):
21: * Felix Gnass [fgnass at neteye dot de]
22: *
23: * ***** END LICENSE BLOCK ***** */
24: package org.riotfamily.riot.editor;
25:
26: import org.riotfamily.riot.form.ui.FormController;
27: import org.springframework.util.Assert;
28:
29: /**
30: *
31: */
32: public class FormDefinition extends AbstractObjectEditorDefinition
33: implements FormReference, Cloneable {
34:
35: protected static final String TYPE_FORM = "form";
36:
37: private String discriminatorValue;
38:
39: private String formId;
40:
41: public FormDefinition(EditorRepository editorRepository) {
42: setEditorRepository(editorRepository);
43: }
44:
45: public String getEditorType() {
46: return TYPE_FORM;
47: }
48:
49: public String getFormId() {
50: return formId;
51: }
52:
53: public void setId(String id) {
54: super .setId(id);
55: }
56:
57: public void setFormId(String formId) {
58: this .formId = formId;
59: }
60:
61: public Class getBeanClass() {
62: Assert.notNull(formId,
63: "A formId must be set before calling getBeanClass().");
64: return getEditorRepository().getFormRepository().getBeanClass(
65: formId);
66: }
67:
68: protected String getDefaultName() {
69: return getFormId();
70: }
71:
72: public String getDiscriminatorValue() {
73: return discriminatorValue;
74: }
75:
76: public void setDiscriminatorValue(String discriminatorValue) {
77: this .discriminatorValue = discriminatorValue;
78: }
79:
80: public FormDefinition copy(String idPrefix) {
81: try {
82: FormDefinition copy = (FormDefinition) clone();
83: copy.setId(idPrefix + getId());
84: getEditorRepository().addEditorDefinition(copy);
85: return copy;
86: } catch (CloneNotSupportedException e) {
87: throw new RuntimeException(e);
88: }
89: }
90:
91: protected String getEditorUrlWithinServlet(String objectId,
92: String parentId) {
93: return FormController.getUrl(getId(), objectId, parentId);
94: }
95:
96: }
|