001: /*
002: * $Header: /cvsroot/jvalidate/jvalidate-framework/jvalidate/src/main/java/nl/knowlogy/validation/metadata/PropertyMetadataImpl.java,v 1.4 2007/04/20 12:53:18 roberthofstra Exp $
003: * $Revision: 1.4 $
004: * $Date: 2007/04/20 12:53:18 $
005: *
006: *
007: * Copyright 2004 - 2005 Knowlogy, the Netherlands, www.knowlogy.nl
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package nl.knowlogy.validation.metadata;
023:
024: import java.util.Map;
025:
026: import org.apache.commons.collections.FastHashMap;
027:
028: /**
029: *
030: *
031: * @author Robert
032: */
033:
034: public class PropertyMetadataImpl implements PropertyMetadata {
035:
036: private FastHashMap metadataMap = new FastHashMap();
037:
038: private String propertyName;
039:
040: public PropertyMetadataImpl(String propertyName) {
041: this .propertyName = propertyName;
042: }
043:
044: /*
045: * (non-Javadoc)
046: *
047: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getPropertyName()
048: */
049: public String getPropertyName() {
050: return propertyName;
051: }
052:
053: /*
054: * (non-Javadoc)
055: *
056: * @see nl.knowlogy.validation.metadata.PropertyMetadata#setRequired(boolean)
057: */
058: public void setRequired(Boolean value) {
059: metadataMap.put(PropertyMetadata.REQUIRED, value);
060: }
061:
062: /*
063: * (non-Javadoc)
064: *
065: * @see nl.knowlogy.validation.metadata.PropertyMetadata#isRequired()
066: */
067: public Boolean isRequired() {
068: Boolean value = (Boolean) metadataMap
069: .get(PropertyMetadata.REQUIRED);
070: return value != null ? value : Boolean.FALSE;
071: }
072:
073: public void setMaxLength(Long value) {
074:
075: metadataMap.put(PropertyMetadata.MAX_LENGTH, value);
076: }
077:
078: /*
079: * (non-Javadoc)
080: *
081: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getMaxLength()
082: */
083: public Long getMaxLength() {
084:
085: return (Long) metadataMap.get(PropertyMetadata.MAX_LENGTH);
086: }
087:
088: /*
089: * (non-Javadoc)
090: *
091: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getMaxSize()
092: */
093: public Long getMaxSize() {
094: return (Long) metadataMap.get(PropertyMetadata.MAX_SIZE);
095: }
096:
097: public void setMaxSize(Long value) {
098: metadataMap.put(PropertyMetadata.MAX_SIZE, value);
099:
100: }
101:
102: public void setMinLength(Long value) {
103: metadataMap.put(PropertyMetadata.MIN_LENGTH, value);
104: }
105:
106: /*
107: * (non-Javadoc)
108: *
109: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getMinLength()
110: */
111: public Long getMinLength() {
112: return (Long) metadataMap.get(PropertyMetadata.MIN_LENGTH);
113: }
114:
115: /*
116: * (non-Javadoc)
117: *
118: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getMinSize()
119: */
120: public Long getMinSize() {
121: return (Long) metadataMap.get(PropertyMetadata.MIN_SIZE);
122: }
123:
124: public void setMinSize(Long value) {
125: metadataMap.put(PropertyMetadata.MIN_SIZE, value);
126:
127: }
128:
129: /*
130: * (non-Javadoc)
131: *
132: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getRegEx()
133: */
134: public String getPattern() {
135:
136: return (String) metadataMap.get(PropertyMetadata.PATTERN);
137: }
138:
139: public void setPattern(String pattern) {
140:
141: metadataMap.put(PropertyMetadata.PATTERN, pattern);
142:
143: }
144:
145: /*
146: * (non-Javadoc)
147: *
148: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getAllowedValues()
149: */
150: public String getAllowedValues() {
151:
152: return (String) metadataMap
153: .get(PropertyMetadata.ALLOWED_VALUES);
154: }
155:
156: public void setAllowedValues(String value) {
157: metadataMap.put(PropertyMetadata.ALLOWED_VALUES, value);
158:
159: }
160:
161: public void addMetadata(String name, Object value) {
162: //check if name is one of registred
163: metadataMap.setFast(false);
164: try {
165: metadataMap.put(name, value);
166: } finally {
167: metadataMap.setFast(true);
168: }
169: }
170:
171: /*
172: * (non-Javadoc)
173: *
174: * @see nl.knowlogy.validation.metadata.PropertyMetadata#getMetadata()
175: */
176: public Map getMetadata() {
177: return metadataMap;
178: }
179: }
|