1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 /* 24 * Properties.java 25 * 26 * Created on 1. Oktober 2003, 17:16 27 */ 28 package com.sun.star.wizards.common; 29 30 import com.sun.star.beans.PropertyValue; 31 import java.util.*; 32 33 /** 34 * Simplifies handling Arrays of PropertyValue. 35 * To make a use of this class, instantiate it, and call 36 * the put(propName,propValue) method. 37 * caution: propName should always be a String. 38 * When finished, call the getProperties() method to get an array of the set properties. 39 * @author rp 40 */ 41 public class Properties extends Hashtable 42 { 43 getPropertyValue(PropertyValue[] props, String propName)44 public static Object getPropertyValue(PropertyValue[] props, String propName) 45 { 46 for (int i = 0; i < props.length; i++) 47 { 48 if (propName.equals(props[i].Name)) 49 { 50 return props[i].Value; 51 } 52 } 53 throw new IllegalArgumentException("Property '" + propName + "' not found."); 54 } 55 hasPropertyValue(PropertyValue[] props, String propName)56 public static boolean hasPropertyValue(PropertyValue[] props, String propName) 57 { 58 for (int i = 0; i < props.length; i++) 59 { 60 if (propName.equals(props[i].Name)) 61 { 62 return true; 63 } 64 } 65 return false; 66 } 67 getProperties()68 public PropertyValue[] getProperties() 69 { 70 return getProperties(this); 71 } 72 getProperties(Map map)73 public static PropertyValue[] getProperties(Map map) 74 { 75 PropertyValue[] pv = new PropertyValue[map.size()]; 76 77 Iterator it = map.keySet().iterator(); 78 for (int i = 0; i < pv.length; i++) 79 { 80 pv[i] = createProperty((String) it.next(), map); 81 } 82 return pv; 83 } 84 createProperty(String name, Map map)85 public static PropertyValue createProperty(String name, Map map) 86 { 87 return createProperty(name, map.get(name)); 88 } 89 createProperty(String name, Object value)90 public static PropertyValue createProperty(String name, Object value) 91 { 92 PropertyValue pv = new PropertyValue(); 93 pv.Name = name; 94 pv.Value = value; 95 return pv; 96 } 97 createProperty(String name, Object value, int handle)98 public static PropertyValue createProperty(String name, Object value, int handle) 99 { 100 PropertyValue pv = createProperty(name, value); 101 pv.Handle = handle; 102 return pv; 103 } 104 convertToPropertyValueArray(Object[] _oObjectArray)105 public static PropertyValue[] convertToPropertyValueArray(Object[] _oObjectArray) 106 { 107 PropertyValue[] retproperties = null; 108 if (_oObjectArray != null) 109 { 110 if (_oObjectArray.length > 0) 111 { 112 retproperties = new PropertyValue[_oObjectArray.length]; 113 for (int i = 0; i < _oObjectArray.length; i++) 114 { 115 retproperties[i] = (PropertyValue) _oObjectArray[i]; 116 } 117 } 118 } 119 return retproperties; 120 } 121 } 122