2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache 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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.util
.xml
;
18 import com
.intellij
.openapi
.Disposable
;
19 import com
.intellij
.openapi
.util
.Disposer
;
20 import com
.intellij
.psi
.xml
.XmlTag
;
22 import java
.lang
.reflect
.Type
;
23 import java
.util
.HashMap
;
29 public class TypeChooserManager
{
30 private final Map
<Type
, TypeChooser
> myClassChoosers
= new HashMap
<Type
, TypeChooser
>();
32 public TypeChooser
getTypeChooser(final Type type
) {
33 final TypeChooser typeChooser
= myClassChoosers
.get(type
);
34 return typeChooser
!= null ? typeChooser
: new TypeChooser() {
35 public Type
chooseType(final XmlTag tag
) {
39 public void distinguishTag(final XmlTag tag
, final Type aClass
) {
42 public Type
[] getChooserTypes() {
43 return new Type
[]{type
};
48 public void registerTypeChooser(final Type aClass
, final TypeChooser typeChooser
, Disposable parentDisposable
) {
49 registerTypeChooser(aClass
, typeChooser
);
50 Disposer
.register(parentDisposable
, new Disposable() {
51 public void dispose() {
52 unregisterTypeChooser(aClass
);
57 public void registerTypeChooser(final Type aClass
, final TypeChooser typeChooser
) {
58 myClassChoosers
.put(aClass
, typeChooser
);
61 public void unregisterTypeChooser(Type aClass
) {
62 myClassChoosers
.remove(aClass
);
65 public final void copyFrom(TypeChooserManager manager
) {
66 myClassChoosers
.putAll(manager
.myClassChoosers
);