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
.reflect
;
18 import com
.intellij
.openapi
.util
.Key
;
19 import com
.intellij
.util
.SmartList
;
20 import com
.intellij
.util
.xml
.Converter
;
21 import com
.intellij
.util
.xml
.XmlName
;
22 import com
.intellij
.util
.xml
.impl
.ConvertAnnotationImpl
;
23 import com
.intellij
.util
.xml
.impl
.DomChildDescriptionImpl
;
24 import gnu
.trove
.THashMap
;
25 import org
.jetbrains
.annotations
.NotNull
;
27 import java
.lang
.annotation
.Annotation
;
28 import java
.lang
.reflect
.Type
;
29 import java
.util
.List
;
35 public class DomExtensionImpl
implements DomExtension
{
36 public static final Key
<List
<DomExtender
>> DOM_EXTENDER_KEY
= Key
.create("Dom.Extender");
37 private final XmlName myXmlName
;
38 private final Type myType
;
39 private Converter myConverter
;
40 private final List
<Annotation
> myCustomAnnos
= new SmartList
<Annotation
>();
41 private boolean mySoft
;
42 private int myCount
= 1;
43 private Map myUserMap
;
45 public DomExtensionImpl(final Type type
, final XmlName xmlName
) {
51 public XmlName
getXmlName() {
56 public Type
getType() {
60 public DomExtension
setConverter(@NotNull Converter converter
) {
61 return setConverter(converter
, false);
64 public final DomExtension
setConverter(@NotNull final Converter converter
, final boolean soft
) {
65 myConverter
= converter
;
70 public DomExtension
addCustomAnnotation(@NotNull final Annotation anno
) {
71 myCustomAnnos
.add(anno
);
75 public <T
> void putUserData(final Key
<T
> key
, final T value
) {
76 if (myUserMap
== null) myUserMap
= new THashMap();
77 myUserMap
.put(key
, value
);
80 public DomExtension
addExtender(final DomExtender extender
) {
81 if (myUserMap
== null || !myUserMap
.containsKey(DOM_EXTENDER_KEY
)) {
82 putUserData(DOM_EXTENDER_KEY
, new SmartList
<DomExtender
>());
84 ((List
<DomExtender
>)myUserMap
.get(DOM_EXTENDER_KEY
)).add(extender
);
88 public final DomExtensionImpl
setCount(final int count
) {
93 public final int getCount() {
97 public final <T
extends DomChildDescriptionImpl
> T
addAnnotations(T t
) {
98 t
.setUserMap(myUserMap
);
99 if (myConverter
!= null) {
100 t
.addCustomAnnotation(new ConvertAnnotationImpl(myConverter
, mySoft
));
102 for (final Annotation anno
: myCustomAnnos
) {
103 t
.addCustomAnnotation(anno
);