View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.validation.constraint.provider;
17  
18  import org.kuali.rice.krad.datadictionary.CollectionDefinition;
19  import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
20  import org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint;
21  import org.kuali.rice.krad.datadictionary.validation.constraint.ExistenceConstraint;
22  import org.kuali.rice.krad.datadictionary.validation.constraint.resolver.ConstraintResolver;
23  import org.kuali.rice.krad.datadictionary.validation.constraint.resolver.DefinitionConstraintResolver;
24  
25  import java.util.HashMap;
26  
27  /**
28   * An object that looks up constraints for attribute definitions by constraint type. This can either by instantiated by
29   * dependency
30   * injection, in which case a map of class names to constraint resolvers can be injected, or the default map can be
31   * constructed by
32   * calling the init() method immediately after instantiation.
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class CollectionDefinitionConstraintProvider extends BaseConstraintProvider<CollectionDefinition> {
37  
38      @Override
39      public void init() {
40          resolverMap = new HashMap<String, ConstraintResolver<CollectionDefinition>>();
41          resolverMap.put(ExistenceConstraint.class.getName(), new DefinitionConstraintResolver<CollectionDefinition>());
42          resolverMap.put(CollectionSizeConstraint.class.getName(),
43                  new DefinitionConstraintResolver<CollectionDefinition>());
44      }
45  
46      /**
47       * @see org.kuali.rice.krad.datadictionary.validation.constraint.provider.ConstraintProvider#isSupported(org.kuali.rice.krad.datadictionary.validation.capability.Constrainable)
48       */
49      @Override
50      public boolean isSupported(Constrainable definition) {
51  
52          if (definition instanceof CollectionDefinition) {
53              return true;
54          }
55  
56          return false;
57      }
58  
59  }