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
.xml
.util
;
18 import com
.intellij
.psi
.PsiElement
;
19 import com
.intellij
.psi
.xml
.XmlDocument
;
20 import com
.intellij
.psi
.xml
.XmlFile
;
21 import com
.intellij
.psi
.xml
.XmlTag
;
22 import com
.intellij
.xml
.XmlElementDescriptor
;
23 import com
.intellij
.xml
.XmlNSDescriptor
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.annotations
.Nullable
;
27 import java
.util
.ArrayList
;
28 import java
.util
.Arrays
;
29 import java
.util
.Iterator
;
30 import java
.util
.List
;
33 * Created by IntelliJ IDEA.
37 * To change this template use Options | File Templates.
39 public class XmlNSDescriptorSequence
implements XmlNSDescriptor
{
40 final List
<XmlNSDescriptor
> sequence
= new ArrayList
<XmlNSDescriptor
>();
42 public XmlNSDescriptorSequence(){
45 public XmlNSDescriptorSequence(XmlNSDescriptor
[] descriptors
){
46 for(int i
= 0; i
< descriptors
.length
; i
++){
47 final XmlNSDescriptor descriptor
= descriptors
[i
];
52 public void add(XmlNSDescriptor descriptor
){
53 sequence
.add(descriptor
);
56 public XmlElementDescriptor
getElementDescriptor(@NotNull XmlTag tag
){
57 final Iterator iterator
= sequence
.iterator();
58 while(iterator
.hasNext()){
59 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
60 final XmlElementDescriptor elementDescriptor
= descriptor
.getElementDescriptor(tag
);
61 if(elementDescriptor
!= null) return elementDescriptor
;
67 public XmlElementDescriptor
[] getRootElementsDescriptors(@Nullable final XmlDocument document
) {
68 final List
<XmlElementDescriptor
> descriptors
= new ArrayList
<XmlElementDescriptor
>();
69 final Iterator iterator
= sequence
.iterator();
70 while(iterator
.hasNext()){
71 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
72 descriptors
.addAll(Arrays
.asList(descriptor
.getRootElementsDescriptors(document
)));
75 return descriptors
.toArray(new XmlElementDescriptor
[descriptors
.size()]);
78 public XmlFile
getDescriptorFile(){
79 final Iterator iterator
= sequence
.iterator();
80 while(iterator
.hasNext()){
81 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
82 final XmlFile file
= descriptor
.getDescriptorFile();
83 if(file
!= null) return file
;
88 public List
<XmlNSDescriptor
> getSequence(){
92 public boolean isHierarhyEnabled() {
93 final Iterator iterator
= sequence
.iterator();
94 while(iterator
.hasNext()){
95 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
96 if(descriptor
.isHierarhyEnabled()) return true;
101 public PsiElement
getDeclaration(){
102 final Iterator iterator
= sequence
.iterator();
103 while(iterator
.hasNext()){
104 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
105 final PsiElement declaration
= descriptor
.getDeclaration();
106 if(declaration
!= null) return declaration
;
111 public String
getName(PsiElement context
){
112 final Iterator iterator
= sequence
.iterator();
113 while(iterator
.hasNext()){
114 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
115 final String name
= descriptor
.getName(context
);
116 if(name
!= null) return name
;
121 public String
getName(){
122 final Iterator iterator
= sequence
.iterator();
123 while(iterator
.hasNext()){
124 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
125 final String name
= descriptor
.getName();
126 if(name
!= null) return name
;
131 public void init(PsiElement element
){
132 final Iterator iterator
= sequence
.iterator();
133 while(iterator
.hasNext()){
134 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
135 descriptor
.init(element
);
139 public Object
[] getDependences(){
140 final List
<Object
> ret
= new ArrayList
<Object
>();
141 final Iterator iterator
= sequence
.iterator();
142 while(iterator
.hasNext()){
143 final XmlNSDescriptor descriptor
= (XmlNSDescriptor
) iterator
.next();
144 ret
.addAll(Arrays
.asList(descriptor
.getDependences()));
146 return ret
.toArray();