001: /*
002: * Copyright 2006-2007 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.romaframework.core.command;
017:
018: import java.io.Serializable;
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: /*
023: * Context for the Command execution. It contains the Context ID and multiple parameters using an HashMap<String,Object>.
024: */
025: public class CommandContext implements Serializable {
026:
027: private long id = -1;
028: private Map<String, Object> parameters;
029:
030: public CommandContext() {
031: this (-1);
032: }
033:
034: public CommandContext(long iId) {
035: this (new HashMap<String, Object>());
036: id = iId;
037: }
038:
039: public CommandContext(Map<String, Object> parameters) {
040: this .parameters = parameters;
041: }
042:
043: public void clear() {
044: id = -1;
045: parameters.clear();
046: }
047:
048: public Object getParameter(String iName) {
049: return parameters.get(iName);
050: }
051:
052: public void setParameter(String iName, Object iValue) {
053: if (parameters == null) {
054: parameters = new HashMap<String, Object>();
055: }
056: parameters.put(iName, iValue);
057: }
058:
059: public Map<String, Object> getParameters() {
060: return parameters;
061: }
062:
063: public void setParameters(Map<String, Object> parameters) {
064: this .parameters = parameters;
065: }
066:
067: public long getId() {
068: return id;
069: }
070:
071: public void setId(long id) {
072: this .id = id;
073: }
074:
075: public Integer getInt(String iName) {
076: return (Integer) parameters.get(iName);
077: }
078:
079: public String getString(String iName) {
080: return (String) parameters.get(iName);
081: }
082:
083: public Short getShort(String iName) {
084: return (Short) parameters.get(iName);
085: }
086:
087: public Long getLong(String iName) {
088: return (Long) parameters.get(iName);
089: }
090:
091: public Float getFloat(String iName) {
092: return (Float) parameters.get(iName);
093: }
094:
095: public Double getDouble(Long iName) {
096: return (Double) parameters.get(iName);
097: }
098:
099: public Byte getByte(Long iName) {
100: return (Byte) parameters.get(iName);
101: }
102: }
|