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