KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > editor > FormDefinition


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * 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  */

33 public class FormDefinition extends AbstractObjectEditorDefinition
34         implements FormReference, Cloneable JavaDoc {
35
36     protected static final String JavaDoc TYPE_FORM = "form";
37
38     private String JavaDoc discriminatorValue;
39
40     private String JavaDoc formId;
41
42
43     public FormDefinition(EditorRepository editorRepository) {
44         setEditorRepository(editorRepository);
45     }
46
47     public String JavaDoc getEditorType() {
48         return TYPE_FORM;
49     }
50     
51     public String JavaDoc getFormId() {
52         return formId;
53     }
54
55     public void setId(String JavaDoc id) {
56         super.setId(id);
57     }
58
59     public void setFormId(String JavaDoc formId) {
60         this.formId = formId;
61     }
62
63     public Class JavaDoc getBeanClass() {
64         Assert.notNull(formId, "A formId must be set before calling getBeanClass().");
65         return getEditorRepository().getFormRepository().getBeanClass(formId);
66     }
67
68     protected String JavaDoc getDefaultName() {
69         return getFormId();
70     }
71
72     public String JavaDoc getDiscriminatorValue() {
73         return discriminatorValue;
74     }
75
76     public void setDiscriminatorValue(String JavaDoc discriminatorValue) {
77         this.discriminatorValue = discriminatorValue;
78     }
79
80     public FormDefinition copy(String JavaDoc idPrefix) {
81         try {
82             FormDefinition copy = (FormDefinition) clone();
83             copy.setId(idPrefix + getId());
84             getEditorRepository().addEditorDefinition(copy);
85             return copy;
86         }
87         catch (CloneNotSupportedException JavaDoc e) {
88             throw new RuntimeException JavaDoc(e);
89         }
90     }
91
92     protected String JavaDoc getEditorUrlWithinServlet(String JavaDoc objectId, String JavaDoc parentId) {
93         return FormController.getUrl(getId(), objectId, parentId);
94     }
95
96 }
97
Popular Tags