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 package org.apache.openoffice.comp.sdbc.dbtools.util; 23 24 import java.util.Map; 25 26 import com.sun.star.container.ElementExistException; 27 import com.sun.star.container.NoSuchElementException; 28 import com.sun.star.container.XNameContainer; 29 import com.sun.star.lang.IllegalArgumentException; 30 import com.sun.star.lang.WrappedTargetException; 31 import com.sun.star.uno.Type; 32 33 public class MapToXNameContainerAdapter extends MapToXNameAccessAdapter implements XNameContainer { MapToXNameContainerAdapter(Map<String,Object> map, Object lock, Type elementType)34 public MapToXNameContainerAdapter(Map<String,Object> map, Object lock, Type elementType) { 35 super(map, lock, elementType); 36 } 37 38 // XNameContainer: 39 40 @Override insertByName(String key, Object value)41 public void insertByName(String key, Object value) 42 throws IllegalArgumentException, ElementExistException, 43 WrappedTargetException { 44 synchronized (lock) { 45 if (map.containsKey(key)) { 46 throw new ElementExistException(); 47 } 48 map.put(key, value); 49 } 50 } 51 52 @Override removeByName(String key)53 public void removeByName(String key) 54 throws NoSuchElementException, WrappedTargetException { 55 synchronized (lock) { 56 if (map.containsKey(key)) { 57 map.remove(key); 58 } else { 59 throw new NoSuchElementException(); 60 } 61 } 62 } 63 64 // XNameReplace: 65 66 @Override replaceByName(String key, Object value)67 public void replaceByName(String key, Object value) 68 throws IllegalArgumentException, NoSuchElementException, 69 WrappedTargetException { 70 synchronized (lock) { 71 if (!map.containsKey(key)) { 72 throw new NoSuchElementException(); 73 } 74 map.put(key, value); 75 } 76 } 77 } 78