KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > impl > EValidatorRegistryImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2004 IBM Corporation and others.
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  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: EValidatorRegistryImpl.java,v 1.4 2005/06/08 06:20:10 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.impl;
18
19
20 import java.util.HashMap JavaDoc;
21
22 import org.eclipse.emf.ecore.EPackage;
23 import org.eclipse.emf.ecore.EValidator;
24
25 import org.eclipse.emf.ecore.util.EObjectValidator;
26
27
28 /**
29  * An implementation of a validator registry.
30  */

31 public class EValidatorRegistryImpl extends HashMap JavaDoc implements EValidator.Registry
32 {
33   protected EValidator.Registry delegateRegistry;
34
35   public EValidatorRegistryImpl()
36   {
37   }
38
39   public EValidatorRegistryImpl(EValidator.Registry delegateRegistry)
40   {
41     this.delegateRegistry = delegateRegistry;
42   }
43
44   public Object JavaDoc get(Object JavaDoc key)
45   {
46     Object JavaDoc eValidator = super.get(key);
47     if (eValidator instanceof EValidator.Descriptor)
48     {
49       EValidator.Descriptor eValidatorDescriptor = (EValidator.Descriptor)eValidator;
50       eValidator = eValidatorDescriptor.getEValidator();
51       put(key, eValidator);
52       return eValidator;
53     }
54     else if (eValidator != null)
55     {
56       return eValidator;
57     }
58     else
59     {
60       return delegatedGet(key);
61     }
62   }
63
64   public EValidator getEValidator(EPackage ePackage)
65   {
66     return (EValidator)get(ePackage);
67   }
68
69   protected Object JavaDoc delegatedGet(Object JavaDoc key)
70   {
71     if (delegateRegistry != null)
72     {
73       return delegateRegistry.get(key);
74     }
75
76     return key == null ? EObjectValidator.INSTANCE : null;
77   }
78
79   public boolean containsKey(Object JavaDoc key)
80   {
81     return super.containsKey(key) || delegateRegistry != null && delegateRegistry.containsKey(key);
82   }
83 }
84
Popular Tags