1 package pl.caltha.forms.internal;
2
3 import org.xml.sax.SAXException;
4
5 import pl.caltha.forms.ConstructionException;
6 import pl.caltha.forms.internal.util.Util;
7
8 /***
9 * Builds form-tool Form objects based on SAX events.
10 *
11 * @author <a href="mailto:zwierzem@ngo.pl">Damian Gajda</a>
12 * @version $Id: FormBuilder.java,v 1.3 2005/03/23 07:52:16 zwierzem Exp $
13 */
14 public class FormBuilder
15 extends pl.caltha.forms.internal.util.AbstractBuilder
16 {
17 /*** Form object that is being built. */
18 private FormImpl buildForm;
19
20 public FormBuilder(String acceptedNamespace, String schemaURI)
21 {
22 super(acceptedNamespace, schemaURI);
23 }
24
25 public void startBuild(Object builtObject)
26 throws ConstructionException
27 {
28 buildForm = (FormImpl)builtObject;
29 }
30
31 public void endBuild(Object builtObject)
32 throws ConstructionException
33 {
34 }
35
36 protected void startElement(String elementName, org.xml.sax.Attributes atts) throws SAXException
37 {
38
39 String uri = Util.expandURI(definitionURI, Util.getSAXAttributeVal(atts, "href"));
40
41 if("model".equals(elementName))
42 {
43 buildForm.instanceSchemaURI = uri;
44 }
45 else if("instance".equals(elementName))
46 {
47 buildForm.defaultInstanceURI = uri;
48 }
49 else if("interface".equals(elementName))
50 {
51 buildForm.uiURI = uri;
52 }
53 else if("bind".equals(elementName))
54 {
55 try
56 {
57 buildForm.addBindElement(new pl.caltha.forms.internal.model.Bind(atts));
58 }
59 catch(ConstructionException e)
60 {
61 throw new SAXException("Error adding bind element ("+locator.getSystemId()+" "+locator.getLineNumber()+":"+locator.getColumnNumber()+")", e);
62 }
63 }
64 else if("submitInfo".equals(elementName))
65 {
66 buildForm.submitInfo = new pl.caltha.forms.internal.model.SubmitInfo(atts);
67 }
68 }
69 }