use insert function instead of for loop
[LibreOffice.git] / qadevOOo / runner / helper / ConfigurationRead.java
blob72346a2e7dadd555d7cca15f7e2712650aaf4d27
1 /*
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 .
18 package helper;
20 import com.sun.star.lang.XMultiServiceFactory;
21 import com.sun.star.container.XHierarchicalNameAccess;
22 import com.sun.star.container.NoSuchElementException;
23 import com.sun.star.beans.PropertyValue;
24 import com.sun.star.beans.PropertyState;
25 import com.sun.star.uno.UnoRuntime;
27 /**
28 * Read configuration settings.
30 public class ConfigurationRead {
32 private XHierarchicalNameAccess root = null;
34 /**
35 * Creates new ConfigurationRead
36 * @param xMSF An instance of service
37 * "com.sun.star.configuration.ConfigurationProvider"
38 * @param rootnode The root of the configuration nodes.
40 private ConfigurationRead(XMultiServiceFactory xMSF, String rootnode) {
42 PropertyValue [] nodeArgs = new PropertyValue [1];
43 PropertyValue nodepath = new PropertyValue();
44 nodepath.Name = "nodepath";
45 nodepath.Value = rootnode;
46 nodepath.Handle = -1;
47 nodepath.State = PropertyState.DEFAULT_VALUE;
48 nodeArgs[0]=nodepath;
50 try {
51 Object rootObject = xMSF.createInstanceWithArguments(
52 "com.sun.star.configuration.ConfigurationAccess",
53 nodeArgs);
55 root = UnoRuntime.queryInterface(
56 XHierarchicalNameAccess.class, rootObject);
58 catch(com.sun.star.uno.Exception e) {
59 e.printStackTrace();
63 /**
64 * Creates new ConfigurationRead. This uses "org.openoffice.Setup"
65 * as default root name.
66 * @param xMSF An instance of service
67 * "com.sun.star.configuration.ConfigurationProvider"
69 public ConfigurationRead(XMultiServiceFactory xMSF) {
70 this(xMSF, "org.openoffice.Setup");
73 /**
74 * Get contents of a node by its hierarchical name.
75 * @param name The hierarchical name of the node.
76 * @return The contents as an object
78 public Object getByHierarchicalName(String name) throws NoSuchElementException {
79 return root.getByHierarchicalName(name);