View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.model;
19  
20  import org.vectomatic.svg.edit.client.command.IFactoryInstantiator;
21  
22  /**
23   * Base class for metadata
24   * @author laaglu
25   * @param <T>
26   * The metadata type
27   * @param <U>
28   * The javascript type which provides the property or object
29   */
30  public abstract class MetadataBase<T,U> implements IMetadata<T,U> {
31  	protected String propertyName;
32  	protected String description;
33  	protected IFieldFactory fieldFactory;
34  	protected ModelCategory<U> category;
35  	protected IFactoryInstantiator<?> factory;
36  	protected IValidator<T,U> validator;
37  
38  	public MetadataBase(String propertyName, String description, IFieldFactory fieldFactory, IFactoryInstantiator<?> factory, IValidator<T,U> validator) {
39  		this.propertyName = propertyName;
40  		this.description = description;
41  		this.fieldFactory = fieldFactory;
42  		this.factory = factory;
43  		this.validator = validator;
44  	}
45  
46  	@Override
47  	public String getName() {
48  		return propertyName;
49  	}
50  	@Override
51  	public String getDescription() {
52  		return description;
53  	}
54  	@Override
55  	public IFieldFactory getFieldFactory() {
56  		return fieldFactory;
57  	}
58  	@Override
59  	public IFactoryInstantiator<?> getCommandFactory() {
60  		return factory;
61  	}
62  	@Override
63  	public ModelCategory<U> getCategory() {
64  		return category;
65  	}
66  	@Override
67  	public ValidationError validate(U model, T value) {
68  		return (validator == null) ? null : validator.validate(model, value);
69  	}
70  }