001 package com.thaiopensource.validate;
002
003 import com.thaiopensource.util.PropertyMap;
004 import com.thaiopensource.util.PropertyId;
005 import com.thaiopensource.util.PropertyMapBuilder;
006
007 public abstract class AbstractSchema implements Schema {
008 private final PropertyMap properties;
009
010 public AbstractSchema() {
011 this(PropertyMap.EMPTY);
012 }
013
014 public AbstractSchema(PropertyMap properties) {
015 this.properties = properties;
016 }
017
018 public AbstractSchema(PropertyMap properties, PropertyId[] supportedPropertyIds) {
019 this(filterProperties(properties, supportedPropertyIds));
020 }
021
022 public PropertyMap getProperties() {
023 return properties;
024 }
025
026 static public PropertyMap filterProperties(PropertyMap properties, PropertyId[] supportedPropertyIds) {
027 PropertyMapBuilder builder = new PropertyMapBuilder();
028 for (int i = 0; i < supportedPropertyIds.length; i++) {
029 Object value = properties.get(supportedPropertyIds[i]);
030 if (value != null)
031 builder.put(supportedPropertyIds[i], value);
032 }
033 return builder.toPropertyMap();
034 }
035 }