001: /**
002: * Copyright 2006 Webmedia Group Ltd.
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: **/package org.araneaframework.tests.mock;
016:
017: import java.util.HashSet;
018: import java.util.Set;
019: import org.araneaframework.Environment;
020: import org.araneaframework.uilib.form.Control;
021: import org.araneaframework.uilib.form.Converter;
022: import org.araneaframework.uilib.form.FormElementContext;
023:
024: /**
025: * @author Taimo Peelo (taimo@araneaframework.org)
026: */
027: public class MockFormElementContext implements FormElementContext {
028: private Set errors;
029: private Environment environment;
030:
031: private String label;
032: private boolean mandatory;
033: private boolean disabled;
034: private boolean read;
035: private Object value;
036:
037: public MockFormElementContext() {
038: }
039:
040: public MockFormElementContext(String label, boolean mandatory,
041: boolean disabled) {
042: super ();
043: this .label = label;
044: this .mandatory = mandatory;
045: this .disabled = disabled;
046: }
047:
048: public boolean isDisabled() {
049: return disabled;
050: }
051:
052: public void setDisabled(boolean disabled) {
053: this .disabled = disabled;
054: }
055:
056: public String getLabel() {
057: return label;
058: }
059:
060: public void setLabel(String label) {
061: this .label = label;
062: }
063:
064: public boolean isMandatory() {
065: return mandatory;
066: }
067:
068: public void setMandatory(boolean mandatory) {
069: this .mandatory = mandatory;
070: }
071:
072: public boolean isRead() {
073: return read;
074: }
075:
076: public void setRead(boolean read) {
077: this .read = read;
078: }
079:
080: public Object getValue() {
081: return value;
082: }
083:
084: public void setValue(Object value) {
085: this .value = value;
086: }
087:
088: public Set getErrors() {
089: if (errors == null)
090: errors = new HashSet();
091: return errors;
092: }
093:
094: public Control getControl() {
095: // TODO Auto-generated method stub
096: return null;
097: }
098:
099: public Converter getConverter() {
100: // TODO Auto-generated method stub
101: return null;
102: }
103:
104: public void addError(String error) {
105: getErrors().add(error);
106: }
107:
108: public void addErrors(Set errors) {
109: getErrors().addAll(errors);
110: }
111:
112: public Environment getEnvironment() {
113: return environment;
114: }
115:
116: public boolean isValid() {
117: return (errors == null || errors.size() == 0);
118: }
119:
120: public void clearErrors() {
121: errors.clear();
122: }
123: }
|