update copyright
[fedora-idea.git] / xml / dom-impl / src / com / intellij / util / xml / impl / PhysicalDomParentStrategy.java
bloba6f1b2983194325093f2a9a81da2e961836cbe84
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.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;
24 /**
25 * @author peter
27 public class PhysicalDomParentStrategy implements DomParentStrategy {
28 private XmlElement myElement;
29 private DomManagerImpl myDomManager;
31 public PhysicalDomParentStrategy(@NotNull final XmlElement element, DomManagerImpl domManager) {
32 myElement = element;
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;
51 @NotNull
52 public final XmlElement getXmlElement() {
53 return myElement;
56 @NotNull
57 public DomParentStrategy refreshStrategy(final DomInvocationHandler handler) {
58 return this;
61 @NotNull
62 public DomParentStrategy setXmlElement(@NotNull final XmlElement element) {
63 myElement = element;
64 return this;
67 @NotNull
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;
86 return true;
89 public int hashCode() {
90 return myElement.hashCode();