bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / lib / Parameters.java
blob2db421c1142f8bf654b19c995c94213e2db5a232
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 .
19 package lib;
21 import java.util.Iterator;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.Map;
25 import java.util.Set;
27 import com.sun.star.beans.Property;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.beans.XPropertySetInfo;
30 import com.sun.star.beans.XPropertyChangeListener;
31 import com.sun.star.beans.XVetoableChangeListener;
32 import com.sun.star.beans.UnknownPropertyException;
33 import com.sun.star.lang.WrappedTargetException;
34 import com.sun.star.uno.Type;
36 /**
37 * Parameters is a container of String parameters.
38 * @deprecated
41 public class Parameters implements XPropertySet {
42 /* final protected Map parameters;
43 final Parameters defaults; */
44 final protected Map<String, Object> parameters;
45 final Parameters defaults;
46 Property[] props;
48 public Parameters(Map<String, Object> params) {
49 this (params, null);
52 public Parameters(Map<String, Object> params, Parameters defaultParams) {
53 parameters = params;
54 defaults = defaultParams;
55 checkParameters(parameters);
57 Set<String> paramSet = new HashSet<String>(parameters.keySet());
59 if (defaults != null) {
60 Set<String> defSet = defaults.toMap().keySet();
61 paramSet.addAll(defSet);
64 props = new Property[paramSet.size()];
66 int num = 0;
68 for (Iterator<String> i = paramSet.iterator(); i.hasNext(); num++) {
69 String name = i.next();
71 props[num] = new Property(name, num, new Type(String.class), (short)0);
76 public String get(String paramName) {
77 Object res = parameters.get(paramName);
79 if (res != null && res instanceof String)
80 return (String)res;
82 if (defaults != null)
83 return defaults.get(paramName);
85 return null;
88 public Object getPropertyValue(String name) {
89 Object erg = parameters.get(name);
90 if (erg == null && defaults != null)
91 return defaults.getPropertyValue(name);
92 return erg;
95 public void setPropertyValue(String name, Object value) {
96 parameters.put(name, value);
97 int size = props.length;
98 Property[] addProps = new Property[size+1];
99 for (int i=0; i<size; i++)
101 addProps[i] = props[i];
103 addProps[size] = new Property(name, size, new Type(value.getClass()), (short)0);
104 props = addProps;
107 public void addVetoableChangeListener(String name, XVetoableChangeListener l) {
110 public void removeVetoableChangeListener(String name, XVetoableChangeListener l) {
113 public void addPropertyChangeListener(String name, XPropertyChangeListener l) {
116 public void removePropertyChangeListener(String name, XPropertyChangeListener l) {
119 public XPropertySetInfo getPropertySetInfo() {
120 return new XPropertySetInfo() {
121 public Property[] getProperties() {
122 return props;
125 public boolean hasPropertyByName(String name) {
126 for (int i = 0; i < props.length; i++) {
127 Property prop = props[i];
129 if (prop.Name.equals(name)) {
130 return true;
134 return false;
137 public Property getPropertyByName(String name) throws UnknownPropertyException {
138 for (int i = 0; i < props.length; i++) {
139 Property prop = props[i];
141 if (prop.Name.equals(name)) {
142 return prop;
146 throw new UnknownPropertyException(name);
151 public Map<String,Object> toMap() {
152 return new HashMap<String,Object>(parameters) {
153 public String get(String obj) {
154 return Parameters.this.get(obj);
159 private static void checkParameters(Map<String, Object> params) {
160 for (Iterator<String> i = params.keySet().iterator(); i.hasNext();) {
161 Object key = i.next();
163 if (!(key instanceof String)) {
164 throw new IllegalArgumentException(
165 "Wrong key " + key + ", it should be of String type");
168 /* Object value = params.get(key);
170 if (!(value instanceof String)) {
171 throw new IllegalArgumentException(
172 "Wrong value " + value + ", it should be of String type");
173 } */
177 public static String getString(XPropertySet props, String name) {
178 try {
179 return (String)props.getPropertyValue(name);
180 } catch (UnknownPropertyException e) {
181 return null;
182 } catch (WrappedTargetException e) {
183 return null;
187 public static Object get(XPropertySet props, String name) {
188 try {
189 return props.getPropertyValue(name);
190 } catch (UnknownPropertyException e) {
191 return null;
192 } catch (WrappedTargetException e) {
193 return null;
197 public static Map<String, Object> toMap(XPropertySet props) {
198 HashMap<String, Object> result = new HashMap<String, Object>(10);
200 XPropertySetInfo setInfo = props.getPropertySetInfo();
201 Property[] properties = setInfo.getProperties();
203 for (int i = 0; i < properties.length; i++) {
204 String name = properties[i].Name;
205 Object value;
207 try {
208 value = props.getPropertyValue(name);
209 } catch (WrappedTargetException e) {
210 continue;
211 } catch (UnknownPropertyException e) {
212 continue;
215 result.put(name, value);
218 return result;