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 package com.sun.star.report.util; 24 25 import com.sun.star.report.JobDefinitionException; 26 import com.sun.star.report.JobProperties; 27 import com.sun.star.report.ReportEngineMetaData; 28 29 import java.util.HashMap; 30 import java.util.Map; 31 32 33 public class DefaultJobProperties implements JobProperties 34 { 35 36 private final ReportEngineMetaData metaData; 37 private final Map properties; 38 DefaultJobProperties(final ReportEngineMetaData metaData)39 public DefaultJobProperties(final ReportEngineMetaData metaData) 40 { 41 if (metaData == null) 42 { 43 throw new NullPointerException(); 44 } 45 this.properties = new HashMap(); 46 this.metaData = metaData; 47 } 48 getProperty(final String key)49 public Object getProperty(final String key) 50 { 51 return properties.get(key); 52 } 53 setProperty(final String key, final Object value)54 public void setProperty(final String key, final Object value) 55 throws JobDefinitionException 56 { 57 final Class type = metaData.getParameterType(key); 58 if (type == null) 59 { 60 throw new JobDefinitionException("The parameter name is not known: " + key); 61 } 62 if (!type.isInstance(value)) 63 { 64 throw new JobDefinitionException("The parameter value is not understood"); 65 } 66 67 this.properties.put(key, value); 68 } 69 copy()70 public JobProperties copy() 71 { 72 final DefaultJobProperties props = new DefaultJobProperties(metaData); 73 props.properties.putAll(properties); 74 return props; 75 } 76 } 77