1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 6 package org.openoffice.xforms; 7 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; 19 20 /** 21 * 22 * @author fs93730 23 */ 24 public class XMLDocument extends integration.forms.DocumentHelper 25 { 26 private XFormsSupplier m_formsSupplier; 27 private XNameContainer m_forms; 28 29 /* ------------------------------------------------------------------ */ 30 public XMLDocument( XMultiServiceFactory _orb ) throws Exception 31 { 32 super( _orb, implLoadAsComponent( _orb, getDocumentFactoryURL( DocumentType.XMLFORM ) ) ); 33 impl_initialize( getDocument() ); 34 } 35 36 /* ------------------------------------------------------------------ */ 37 public XMLDocument( XMultiServiceFactory _orb, XComponent _document ) 38 { 39 super( _orb, _document ); 40 impl_initialize( _document ); 41 } 42 43 /* ------------------------------------------------------------------ */ 44 private void impl_initialize( XComponent _document ) 45 { 46 m_formsSupplier = (XFormsSupplier)UnoRuntime.queryInterface( XFormsSupplier.class, 47 _document ); 48 49 if ( m_formsSupplier == null ) 50 throw new IllegalArgumentException(); 51 52 m_forms = m_formsSupplier.getXForms(); 53 } 54 55 /* ------------------------------------------------------------------ */ 56 public String[] getXFormModelNames() 57 { 58 return m_forms.getElementNames(); 59 } 60 61 /* ------------------------------------------------------------------ */ 62 public Model getXFormModel( String _modelName ) throws NoSuchElementException 63 { 64 try 65 { 66 return new Model(m_forms.getByName(_modelName)); 67 } 68 catch (WrappedTargetException ex) 69 { 70 throw new NoSuchElementException(); 71 } 72 } 73 74 /* ------------------------------------------------------------------ */ 75 public Model addXFormModel( String _modelName ) 76 { 77 XModel newModel = null; 78 try 79 { 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(); 87 88 m_forms.insertByName(_modelName, newModel); 89 } 90 catch (Exception ex) 91 { 92 ex.printStackTrace(); 93 } 94 return new Model( newModel ); 95 } 96 } 97