View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    * 
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    * 
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.configuration.pojo;
14  
15  import java.io.Serializable;
16  import java.util.Set;
17  
18  import net.sf.oval.configuration.Configurer;
19  import net.sf.oval.configuration.pojo.elements.ClassConfiguration;
20  import net.sf.oval.configuration.pojo.elements.ConstraintSetConfiguration;
21  
22  /**
23   * @author Sebastian Thomschke
24   */
25  public class POJOConfigurer implements Configurer, Serializable
26  {
27  	private static final long serialVersionUID = 1L;
28  
29  	protected Set<ClassConfiguration> classConfigurations;
30  	protected Set<ConstraintSetConfiguration> constraintSetConfigurations;
31  
32  	/**
33  	 * {@inheritDoc}
34  	 */
35  	public ClassConfiguration getClassConfiguration(final Class< ? > clazz)
36  	{
37  		if (classConfigurations != null)
38  		{
39  			for (final ClassConfiguration classConfig : classConfigurations)
40  			{
41  				if (classConfig.type == clazz) return classConfig;
42  			}
43  		}
44  		return null;
45  	}
46  
47  	/**
48  	 * @return the classConfigurations
49  	 */
50  	public Set<ClassConfiguration> getClassConfigurations()
51  	{
52  		return classConfigurations;
53  	}
54  
55  	/**
56  	 * {@inheritDoc}
57  	 */
58  	public ConstraintSetConfiguration getConstraintSetConfiguration(final String constraintSetId)
59  	{
60  		if (constraintSetConfigurations == null) return null;
61  
62  		for (final ConstraintSetConfiguration csc : constraintSetConfigurations)
63  		{
64  			if (constraintSetId.equals(csc.id)) return csc;
65  		}
66  		return null;
67  	}
68  
69  	/**
70  	 * @return the constraintSetConfigurations
71  	 */
72  	public Set<ConstraintSetConfiguration> getConstraintSetConfigurations()
73  	{
74  		return constraintSetConfigurations;
75  	}
76  
77  	/**
78  	 * @param classConfigurations the classConfigurations to set
79  	 */
80  	public void setClassConfigurations(final Set<ClassConfiguration> classConfigurations)
81  	{
82  		this.classConfigurations = classConfigurations;
83  	}
84  
85  	/**
86  	 * @param constraintSetConfigurations the constraintSetConfigurations to set
87  	 */
88  	public void setConstraintSetConfigurations(final Set<ConstraintSetConfiguration> constraintSetConfigurations)
89  	{
90  		this.constraintSetConfigurations = constraintSetConfigurations;
91  	}
92  }