merge the formfield patch from ooo-build
[ooovba.git] / forms / qa / org / openoffice / xforms / XMLDocument.java
blob9ca35b3801da0e5dd0c9f9ff6dd8484b88c5aebe
1 /*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
6 package org.openoffice.xforms;
8 import com.sun.star.container.NoSuchElementException;
9 import com.sun.star.container.XNameContainer;
10 import com.sun.star.lang.WrappedTargetException;
11 import com.sun.star.lang.XComponent;
12 import com.sun.star.lang.XMultiServiceFactory;
13 import com.sun.star.uno.Exception;
14 import com.sun.star.uno.UnoRuntime;
15 import com.sun.star.xforms.XFormsSupplier;
16 import com.sun.star.xforms.XFormsUIHelper1;
17 import com.sun.star.xforms.XModel;
18 import integration.forms.DocumentType;
20 /**
22 * @author fs93730
24 public class XMLDocument extends integration.forms.DocumentHelper
26 private XFormsSupplier m_formsSupplier;
27 private XNameContainer m_forms;
29 /* ------------------------------------------------------------------ */
30 public XMLDocument( XMultiServiceFactory _orb ) throws Exception
32 super( _orb, implLoadAsComponent( _orb, getDocumentFactoryURL( DocumentType.XMLFORM ) ) );
33 impl_initialize( getDocument() );
36 /* ------------------------------------------------------------------ */
37 public XMLDocument( XMultiServiceFactory _orb, XComponent _document )
39 super( _orb, _document );
40 impl_initialize( _document );
43 /* ------------------------------------------------------------------ */
44 private void impl_initialize( XComponent _document )
46 m_formsSupplier = (XFormsSupplier)UnoRuntime.queryInterface( XFormsSupplier.class,
47 _document );
49 if ( m_formsSupplier == null )
50 throw new IllegalArgumentException();
52 m_forms = m_formsSupplier.getXForms();
55 /* ------------------------------------------------------------------ */
56 public String[] getXFormModelNames()
58 return m_forms.getElementNames();
61 /* ------------------------------------------------------------------ */
62 public Model getXFormModel( String _modelName ) throws NoSuchElementException
64 try
66 return new Model(m_forms.getByName(_modelName));
68 catch (WrappedTargetException ex)
70 throw new NoSuchElementException();
74 /* ------------------------------------------------------------------ */
75 public Model addXFormModel( String _modelName )
77 XModel newModel = null;
78 try
80 newModel = (XModel) UnoRuntime.queryInterface( XModel.class,
81 getOrb().createInstance( "com.sun.star.xforms.Model" ) );
82 newModel.setID(_modelName);
83 XFormsUIHelper1 modelHelper = (XFormsUIHelper1) UnoRuntime.queryInterface(
84 XFormsUIHelper1.class, newModel );
85 modelHelper.newInstance( "Instance 1", new String(), true );
86 newModel.initialize();
88 m_forms.insertByName(_modelName, newModel);
90 catch (Exception ex)
92 ex.printStackTrace();
94 return new Model( newModel );