2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 package org
.openoffice
.xforms
;
21 import com
.sun
.star
.container
.NoSuchElementException
;
22 import com
.sun
.star
.container
.XNameContainer
;
23 import com
.sun
.star
.lang
.WrappedTargetException
;
24 import com
.sun
.star
.lang
.XComponent
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.uno
.Exception
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.xforms
.XFormsSupplier
;
29 import com
.sun
.star
.xforms
.XFormsUIHelper1
;
30 import com
.sun
.star
.xforms
.XModel
;
31 import integration
.forms
.DocumentType
;
33 public class XMLDocument
extends integration
.forms
.DocumentHelper
35 private XNameContainer m_forms
;
37 /* ------------------------------------------------------------------ */
38 public XMLDocument( XMultiServiceFactory _orb
) throws Exception
40 super( _orb
, implLoadAsComponent( _orb
, getDocumentFactoryURL( DocumentType
.XMLFORM
) ) );
41 impl_initialize( getDocument() );
44 /* ------------------------------------------------------------------ */
45 private void impl_initialize( XComponent _document
)
47 XFormsSupplier formsSupplier
= UnoRuntime
.queryInterface( XFormsSupplier
.class,
50 if ( formsSupplier
== null )
51 throw new IllegalArgumentException();
53 m_forms
= formsSupplier
.getXForms();
56 /* ------------------------------------------------------------------ */
57 public String
[] getXFormModelNames()
59 return m_forms
.getElementNames();
62 /* ------------------------------------------------------------------ */
63 public Model
getXFormModel( String _modelName
) throws NoSuchElementException
67 return new Model(m_forms
.getByName(_modelName
));
69 catch (WrappedTargetException ex
)
71 throw new NoSuchElementException(ex
);
75 /* ------------------------------------------------------------------ */
76 public Model
addXFormModel( String _modelName
)
78 XModel newModel
= null;
81 newModel
= UnoRuntime
.queryInterface( XModel
.class,
82 getOrb().createInstance( "com.sun.star.xforms.Model" ) );
83 newModel
.setID(_modelName
);
84 XFormsUIHelper1 modelHelper
= UnoRuntime
.queryInterface(
85 XFormsUIHelper1
.class, newModel
);
86 modelHelper
.newInstance( "Instance 1", "", true );
87 newModel
.initialize();
89 m_forms
.insertByName(_modelName
, newModel
);
95 return new Model( newModel
);