1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 package org.openoffice.xforms; 20 21 import com.sun.star.beans.XPropertySet; 22 import com.sun.star.uno.UnoRuntime; 23 import com.sun.star.xforms.XFormsUIHelper1; 24 import com.sun.star.xforms.XModel; 25 import com.sun.star.xml.dom.XNode; 26 27 public class Model 28 { 29 private final XModel m_model; 30 private final XPropertySet m_modelProps; 31 private final XFormsUIHelper1 m_helper; 32 Model( Object _model )33 protected Model( Object _model ) 34 { 35 m_model = UnoRuntime.queryInterface( XModel.class, _model ); 36 m_modelProps = UnoRuntime.queryInterface( XPropertySet.class, _model ); 37 m_helper = UnoRuntime.queryInterface( XFormsUIHelper1.class, 38 m_model ); 39 } 40 41 42 getUIHelper()43 protected XFormsUIHelper1 getUIHelper() 44 { 45 return m_helper; 46 } 47 getDefaultInstance()48 public Instance getDefaultInstance() 49 { 50 return new Instance( this, m_model.getDefaultInstance() ); 51 } 52 53 /** creates a binding for the given DOM node 54 * 55 * @param _node the DOM node to create a binding for 56 * @param _dataTypeClass the data type to be used for the binding 57 */ createBindingForNode( XNode _node, short _dataTypeClass )58 public XPropertySet createBindingForNode( XNode _node, short _dataTypeClass ) 59 { 60 XPropertySet binding = m_helper.getBindingForNode(_node, true); 61 try 62 { 63 String basicTypeName = (String)m_model.getDataTypeRepository().getBasicDataType( _dataTypeClass ). 64 getPropertyValue( "Name" ); 65 binding.setPropertyValue( "Type", basicTypeName ); 66 } 67 catch (Exception ex) 68 { 69 ex.printStackTrace(); 70 } 71 return binding; 72 } 73 setIsDocumentInternalData( boolean _internalData )74 public void setIsDocumentInternalData( boolean _internalData ) 75 { 76 try 77 { 78 m_modelProps.setPropertyValue("ExternalData", Boolean.valueOf(!_internalData)); 79 } 80 catch (Exception ex) 81 { 82 ex.printStackTrace(); 83 } 84 } 85 getIsDocumentInternalData()86 public boolean getIsDocumentInternalData() 87 { 88 boolean isInternalData = false; 89 try 90 { 91 isInternalData = !((Boolean)m_modelProps.getPropertyValue( "ExternalData" )).booleanValue(); 92 } 93 catch (Exception ex) 94 { 95 ex.printStackTrace(); 96 } 97 return isInternalData; 98 } 99 } 100