merge the formfield patch from ooo-build
[ooovba.git] / forms / qa / org / openoffice / xforms / Model.java
bloba4a76f2130bd63865c8ecb342cfa0e5a1eb50d61
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.beans.PropertyVetoException;
9 import com.sun.star.beans.UnknownPropertyException;
10 import com.sun.star.beans.XPropertySet;
11 import com.sun.star.lang.IllegalArgumentException;
12 import com.sun.star.lang.WrappedTargetException;
13 import com.sun.star.uno.UnoRuntime;
14 import com.sun.star.xforms.XFormsUIHelper1;
15 import com.sun.star.xforms.XModel;
16 import com.sun.star.xml.dom.XNode;
18 /** encapsulates an XForms model
20 * @author fs93730
22 public class Model
24 private XModel m_model;
25 private XPropertySet m_modelProps;
26 private XFormsUIHelper1 m_helper;
28 protected Model( Object _model )
30 m_model = (XModel)UnoRuntime.queryInterface( XModel.class, _model );
31 m_modelProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, _model );
32 m_helper = (XFormsUIHelper1)UnoRuntime.queryInterface( XFormsUIHelper1.class,
33 m_model );
36 protected XModel getXModel()
38 return m_model;
41 protected XFormsUIHelper1 getUIHelper()
43 return m_helper;
46 public Instance getDefaultInstance()
48 return new Instance( this, m_model.getDefaultInstance() );
51 /** creates a binding for the given DOM node
53 * @param _node
54 * the DOM node to create a binding for
55 * @param _dataType
56 * the data type to be used for the binding
57 * @return
59 public XPropertySet createBindingForNode( XNode _node, short _dataTypeClass )
61 XPropertySet binding = m_helper.getBindingForNode(_node, true);
62 try
64 String basicTypeName = (String)m_model.getDataTypeRepository().getBasicDataType( _dataTypeClass ).
65 getPropertyValue( "Name" );
66 binding.setPropertyValue( "Type", basicTypeName );
68 catch (Exception ex)
70 ex.printStackTrace();
72 return binding;
75 public void setIsDocumentInternalData( boolean _internalData )
77 try
79 m_modelProps.setPropertyValue("ExternalData", new Boolean(!_internalData));
81 catch (Exception ex)
83 ex.printStackTrace();
87 public boolean getIsDocumentInternalData()
89 boolean isInternalData = false;
90 try
92 isInternalData = !((Boolean)m_modelProps.getPropertyValue( "ExternalData" )).booleanValue();
94 catch (Exception ex)
96 ex.printStackTrace();
98 return isInternalData;