001: /**
002: * LibreSource Community
003: * Copyright (C) 2004-2007 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This software is not a free software; you can modify it under the
007: * LibreSource Enterprise user license but you can't redistribute it.
008: * See licenses details in LSE-user-license.txt
009: *
010: * Initial authors :
011: *
012: * Guillaume Bort / INRIA
013: * Francois Charoy / Universite Nancy 2
014: * Julien Forest / Artenum
015: * Claude Godart / Universite Henry Poincare
016: * Florent Jouille / INRIA
017: * Sebastien Jourdain / INRIA / Artenum
018: * Yves Lerumeur / Artenum
019: * Pascal Molli / Universite Henry Poincare
020: * Gerald Oster / INRIA
021: * Mariarosa Penzi / Artenum
022: * Gerard Sookahet / Artenum
023: * Raphael Tani / INRIA
024: *
025: * Contributors :
026: *
027: * Stephane Bagnier / Artenum
028: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
029: */package org.libresource.form.ejb;
030:
031: import org.libresource.LibresourceResourceBase;
032:
033: import org.libresource.form.FormField;
034: import org.libresource.form.util.FormResourceUtil;
035:
036: import java.util.Iterator;
037: import java.util.Vector;
038:
039: import javax.ejb.CreateException;
040:
041: /**
042: * A libresource Form
043: *
044: * @libresource.resource name="Form" service="LibresourceForm"
045: */
046: public abstract class FormResourceBean extends LibresourceResourceBase {
047: /**
048: * @ejb.create-method
049: */
050: public String ejbCreate(String name) throws CreateException {
051: setId(FormResourceUtil.generateGUID(this ));
052: setName(name);
053: setFormFields(new Vector());
054:
055: return null;
056: }
057:
058: // persistents fields
059:
060: /**
061: * @ejb.persistent-field
062: * @ejb.interface-method
063: * @ejb.value-object match="libresource"
064: * @ejb.transaction type="Supports"
065: */
066: public abstract String getId();
067:
068: /**
069: * @ejb.persistent-field
070: * @ejb.interface-method
071: * @ejb.transaction type="Mandatory"
072: */
073: public abstract void setId(String id);
074:
075: /**
076: * @ejb.interface-method
077: * @ejb.value-object match="libresource"
078: * @ejb.transaction type="Supports"
079: */
080: public String getShortResourceName() {
081: return getName();
082: }
083:
084: /**
085: * @ejb.persistent-field
086: * @ejb.interface-method
087: * @ejb.value-object match="libresource"
088: * @ejb.transaction type="Supports"
089: */
090: public abstract String getName();
091:
092: /**
093: * @ejb.persistent-field
094: * @ejb.interface-method
095: * @ejb.transaction type="Mandatory"
096: */
097: public abstract void setName(String name);
098:
099: /**
100: * @ejb.persistent-field
101: * @ejb.interface-method
102: * @ejb.value-object match="libresource"
103: * @ejb.transaction type="Supports"
104: */
105: public abstract String getDescription();
106:
107: /**
108: * @ejb.persistent-field
109: * @ejb.interface-method
110: * @ejb.transaction type="Mandatory"
111: */
112: public abstract void setDescription(String description);
113:
114: /**
115: * @ejb.persistent-field
116: * @ejb.interface-method
117: * @ejb.value-object match="libresource"
118: * @ejb.transaction type="Supports"
119: */
120: public abstract String getResourceTypeToCreate();
121:
122: /**
123: * @ejb.persistent-field
124: * @ejb.interface-method
125: * @ejb.transaction type="Mandatory"
126: */
127: public abstract void setResourceTypeToCreate(String resourceType);
128:
129: /**
130: * @ejb.persistent-field
131: * @ejb.interface-method
132: * @ejb.value-object match="libresource"
133: * @ejb.transaction type="Supports"
134: */
135: public abstract String getDestinationURI();
136:
137: /**
138: * @ejb.persistent-field
139: * @ejb.interface-method
140: * @ejb.transaction type="Mandatory"
141: */
142: public abstract void setDestinationURI(String destinationURI);
143:
144: /**
145: * @ejb.persistent-field
146: * @ejb.interface-method
147: * @ejb.value-object match="libresource"
148: * @ejb.transaction type="Supports"
149: */
150: public abstract String getRedirectionURI();
151:
152: /**
153: * @ejb.persistent-field
154: * @ejb.interface-method
155: * @ejb.transaction type="Mandatory"
156: */
157: public abstract void setRedirectionURI(String redirectionURI);
158:
159: /**
160: * @ejb.persistent-field
161: * @ejb.interface-method
162: * @ejb.value-object match="libresource"
163: * @ejb.transaction type="Supports"
164: */
165: public abstract Vector getFormFields();
166:
167: /**
168: * @ejb.persistent-field
169: * @ejb.interface-method
170: * @ejb.transaction type="Mandatory"
171: */
172: public abstract void setFormFields(Vector formFields);
173:
174: // business methods
175:
176: /**
177: * @ejb.interface-method
178: */
179: public void addField(int index, FormField field) throws Exception {
180: Vector formFields = getFormFields();
181:
182: if (formFields == null) {
183: formFields = new Vector();
184: }
185:
186: formFields.add(index, field);
187: setFormFields(formFields);
188: }
189:
190: /**
191: * @ejb.interface-method
192: */
193: public void addField(FormField field) throws Exception {
194: Vector formFields = getFormFields();
195:
196: if (formFields == null) {
197: formFields = new Vector();
198: }
199:
200: formFields.add(field);
201: setFormFields(formFields);
202: }
203:
204: /**
205: * @ejb.interface-method
206: */
207: public boolean removeField(String fieldId) throws Exception {
208: Vector formFields = getFormFields();
209:
210: if (formFields == null) {
211: formFields = new Vector();
212: }
213:
214: boolean ok = formFields.remove(new FormField(fieldId));
215: setFormFields(formFields);
216:
217: return ok;
218: }
219:
220: /**
221: * @ejb.interface-method
222: */
223: public void moveFieldUp(String fieldId) throws Exception {
224: Vector formFields = getFormFields();
225:
226: if (formFields == null) {
227: formFields = new Vector();
228: }
229:
230: int pos = formFields.indexOf(new FormField(fieldId));
231:
232: if (pos != -1) {
233: FormField realFormField = (FormField) formFields.get(pos);
234: formFields.remove(pos);
235:
236: if (pos > 0) {
237: pos--;
238: }
239:
240: formFields.add(pos, realFormField);
241: }
242:
243: setFormFields(formFields);
244: }
245:
246: /**
247: * @ejb.interface-method
248: */
249: public void moveFieldDown(String fieldId) throws Exception {
250: Vector formFields = getFormFields();
251:
252: if (formFields == null) {
253: formFields = new Vector();
254: }
255:
256: int pos = formFields.indexOf(new FormField(fieldId));
257:
258: if (pos != -1) {
259: FormField realFormField = (FormField) formFields.get(pos);
260: formFields.remove(pos);
261: pos++;
262: formFields.add(pos, realFormField);
263: }
264:
265: setFormFields(formFields);
266: }
267:
268: /**
269: * @ejb.interface-method
270: */
271: public void resetValues() throws Exception {
272: Vector formFields = getFormFields();
273:
274: if (formFields == null) {
275: formFields = new Vector();
276: }
277:
278: for (Iterator i = formFields.iterator(); i.hasNext();) {
279: ((FormField) i.next()).resetValue();
280: }
281:
282: setFormFields(formFields);
283: }
284: }
|