001: /*
002: * Copyright 2006 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:
017: package org.romaframework.module.admin.domain;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import org.romaframework.aspect.core.annotation.AnnotationConstants;
023: import org.romaframework.aspect.core.annotation.CoreClass;
024: import org.romaframework.aspect.view.annotation.ViewAction;
025: import org.romaframework.aspect.view.annotation.ViewField;
026:
027: @CoreClass(orderFields="name description parameters")
028: public class Environment {
029: protected String name;
030:
031: @ViewField(render="textarea")
032: protected String description;
033:
034: @ViewField(visible=AnnotationConstants.FALSE)
035: protected Map<String, EnvironmentItem> parameters;
036:
037: public Environment() {
038: this (null, null);
039: }
040:
041: public Environment(String iName, String iDescription) {
042: name = iName;
043: description = iDescription;
044: parameters = new HashMap<String, EnvironmentItem>();
045: }
046:
047: @Override
048: public String toString() {
049: return name;
050: }
051:
052: public String getDescription() {
053: return description;
054: }
055:
056: public void setDescription(String iText) {
057: this .description = iText;
058: }
059:
060: public String getName() {
061: return name;
062: }
063:
064: public void setName(String name) {
065: this .name = name;
066: }
067:
068: public Map<String, EnvironmentItem> getParameters() {
069: return parameters;
070: }
071:
072: @ViewField(visible=AnnotationConstants.FALSE)
073: public EnvironmentItem getParameter(String iName) {
074: return parameters.get(iName);
075: }
076:
077: @ViewField(visible=AnnotationConstants.FALSE)
078: public String getParameterValue(String iName, String iDefaultValue) {
079: String value = getParameterValue(iName);
080: if (value == null)
081: return iDefaultValue;
082:
083: return value;
084: }
085:
086: @ViewField(visible=AnnotationConstants.FALSE)
087: public int getParameterValueInteger(String iName, int iDefaultValue) {
088: String value = getParameterValue(iName);
089: if (value == null)
090: return iDefaultValue;
091: return Integer.parseInt(value);
092: }
093:
094: @ViewField(visible=AnnotationConstants.FALSE)
095: public float getParameterValueFloat(String iName,
096: float iDefaultValue) {
097: String value = getParameterValue(iName);
098: if (value == null)
099: return iDefaultValue;
100: return Float.parseFloat(value);
101: }
102:
103: @ViewField(visible=AnnotationConstants.FALSE)
104: public boolean getParameterValueBoolean(String iName,
105: boolean iDefaultValue) {
106: String value = getParameterValue(iName);
107: if (value == null)
108: return iDefaultValue;
109: return Boolean.parseBoolean(value);
110: }
111:
112: @ViewField(visible=AnnotationConstants.FALSE)
113: public String getParameterValue(String iName) {
114: Object value = parameters.get(iName);
115: if (value instanceof EnvironmentItem) {
116: EnvironmentItem item = parameters.get(iName);
117: if (item != null)
118: item.getValue();
119: } else if (value != null)
120: // OLD VERSION
121: return value.toString();
122:
123: return null;
124: }
125:
126: public void setParameter(String iName, EnvironmentItem iValue) {
127: parameters.put(iName, iValue);
128: }
129:
130: public void setParameterValue(String iName, String iValue) {
131: EnvironmentItem item = parameters.get(iName);
132: if (item == null) {
133: item = new EnvironmentItem(iName);
134: parameters.put(iName, item);
135: }
136: item.setValue(iValue);
137: }
138:
139: @ViewAction(visible=AnnotationConstants.FALSE)
140: public void clearParameters() {
141: parameters.clear();
142: }
143: }
|