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
.impl
;
18 import com
.intellij
.psi
.PsiElement
;
19 import com
.intellij
.psi
.xml
.XmlElement
;
20 import com
.intellij
.psi
.xml
.XmlEntityRef
;
21 import com
.intellij
.psi
.xml
.XmlTag
;
22 import org
.jetbrains
.annotations
.NotNull
;
27 public class PhysicalDomParentStrategy
implements DomParentStrategy
{
28 private XmlElement myElement
;
29 private DomManagerImpl myDomManager
;
31 public PhysicalDomParentStrategy(@NotNull final XmlElement element
, DomManagerImpl domManager
) {
33 myDomManager
= domManager
;
36 public DomInvocationHandler
getParentHandler() {
37 final XmlTag parentTag
= getParentTag(myElement
);
38 assert parentTag
!= null;
39 return myDomManager
.getDomHandler(parentTag
);
42 public static XmlTag
getParentTag(final XmlElement xmlElement
) {
43 return (XmlTag
)getParentTagCandidate(xmlElement
);
46 public static PsiElement
getParentTagCandidate(final XmlElement xmlElement
) {
47 final PsiElement parent
= xmlElement
.getParent();
48 return parent
instanceof XmlEntityRef ? parent
.getParent() : parent
;
52 public final XmlElement
getXmlElement() {
57 public DomParentStrategy
refreshStrategy(final DomInvocationHandler handler
) {
62 public DomParentStrategy
setXmlElement(@NotNull final XmlElement element
) {
68 public DomParentStrategy
clearXmlElement() {
69 final DomInvocationHandler parent
= getParentHandler();
70 assert parent
!= null : "write operations should be performed on the DOM having a parent, your DOM may be not very fresh";
71 return new VirtualDomParentStrategy(parent
);
74 public boolean isValid() {
75 return myElement
.isValid();
78 public boolean equals(final Object o
) {
79 if (this == o
) return true;
80 if (!(o
instanceof PhysicalDomParentStrategy
)) return false;
82 final PhysicalDomParentStrategy that
= (PhysicalDomParentStrategy
)o
;
84 if (!myElement
.equals(that
.myElement
)) return false;
89 public int hashCode() {
90 return myElement
.hashCode();