update copyright
[fedora-idea.git] / xml / dom-impl / src / com / intellij / util / xml / reflect / DomExtensionsRegistrarImpl.java
blobfd43c405895f58f1dfd95349a7acdf5073b633f1
1 /*
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.util.SmartList;
19 import com.intellij.util.ReflectionUtil;
20 import com.intellij.util.xml.GenericAttributeValue;
21 import com.intellij.util.xml.XmlName;
22 import gnu.trove.THashSet;
23 import org.jetbrains.annotations.NotNull;
24 import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
26 import java.lang.reflect.Type;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.Set;
31 /**
32 * @author peter
34 public class DomExtensionsRegistrarImpl implements DomExtensionsRegistrar {
35 private final List<DomExtensionImpl> myAttributes = new SmartList<DomExtensionImpl>();
36 private final List<DomExtensionImpl> myFixeds = new SmartList<DomExtensionImpl>();
37 private final List<DomExtensionImpl> myCollections = new SmartList<DomExtensionImpl>();
38 private final Set<Object> myDependencies = new THashSet<Object>();
39 private DomExtensionImpl myCustomChildrenType;
41 public List<DomExtensionImpl> getAttributes() {
42 return myAttributes;
44 public List<DomExtensionImpl> getFixeds() {
45 return myFixeds;
48 public List<DomExtensionImpl> getCollections() {
49 return myCollections;
52 public DomExtensionImpl getCustomChildrenType() {
53 return myCustomChildrenType;
56 @NotNull
57 public final DomExtension registerFixedNumberChildrenExtension(@NotNull final XmlName name, @NotNull final Type type, final int count) {
58 assert count > 0;
59 return addExtension(myFixeds, name, type).setCount(count);
62 @NotNull
63 public DomExtension registerFixedNumberChildExtension(@NotNull final XmlName name, @NotNull final Type type) {
64 return registerFixedNumberChildrenExtension(name, type, 1);
67 @NotNull
68 public DomExtension registerCollectionChildrenExtension(@NotNull final XmlName name, @NotNull final Type type) {
69 return addExtension(myCollections, name, type);
72 @NotNull
73 public DomExtension registerGenericAttributeValueChildExtension(@NotNull final XmlName name, final Type parameterType) {
74 return addExtension(myAttributes, name, ParameterizedTypeImpl.make(GenericAttributeValue.class, new Type[]{parameterType}, null));
77 @NotNull
78 public DomExtension registerAttributeChildExtension(@NotNull final XmlName name, @NotNull final Type type) {
79 assert GenericAttributeValue.class.isAssignableFrom(ReflectionUtil.getRawType(type));
80 return addExtension(myAttributes, name, type);
83 @NotNull
84 public DomExtension registerCustomChildrenExtension(@NotNull final Type type) {
85 assert myCustomChildrenType == null;
86 return myCustomChildrenType = new DomExtensionImpl(type, null);
89 private static DomExtensionImpl addExtension(final List<DomExtensionImpl> list, final XmlName name, final Type type) {
90 final DomExtensionImpl extension = new DomExtensionImpl(type, name);
91 list.add(extension);
92 return extension;
95 public final void addDependencies(Object[] deps) {
96 myDependencies.addAll(Arrays.asList(deps));
99 public Object[] getDependencies() {
100 return myDependencies.toArray();