refactor jsf model
[fedora-idea.git] / source / com / intellij / util / xml / impl / DomFileElementImpl.java
blobaa05f8545dab6f2f9f179dc16d14a77cea047cf8
1 /*
2 * Copyright (c) 2005 Your Corporation. All Rights Reserved.
3 */
4 package com.intellij.util.xml.impl;
6 import com.intellij.psi.PsiLock;
7 import com.intellij.psi.xml.XmlDocument;
8 import com.intellij.psi.xml.XmlFile;
9 import com.intellij.psi.xml.XmlTag;
10 import com.intellij.util.xml.*;
11 import org.jetbrains.annotations.NotNull;
12 import org.jetbrains.annotations.Nullable;
14 /**
15 * @author peter
17 public class DomFileElementImpl<T extends DomElement> implements DomFileElement<T> {
18 private final XmlFile myFile;
19 private final Class<T> myRootElementClass;
20 private final String myRootTagName;
21 private final DomManagerImpl myManager;
22 private T myRootValue;
24 protected DomFileElementImpl(final XmlFile file,
25 final Class<T> rootElementClass,
26 final String rootTagName,
27 final DomManagerImpl manager) {
28 myFile = file;
29 myRootElementClass = rootElementClass;
30 myRootTagName = rootTagName;
31 myManager = manager;
34 public XmlFile getFile() {
35 return myFile;
38 @Nullable
39 public XmlTag getRootTag() {
40 final XmlDocument document = myFile.getDocument();
41 if (document != null) {
42 final XmlTag tag = document.getRootTag();
43 if (tag != null && myRootTagName.equals(tag.getName())) {
44 return tag;
47 return null;
50 public DomManagerImpl getManager() {
51 return myManager;
54 @NotNull
55 public T getRootElement() {
56 synchronized (PsiLock.LOCK) {
57 if (myRootValue == null) {
58 final XmlTag tag = getRootTag();
59 final DomRootInvocationHandler<T> handler = new DomRootInvocationHandler<T>(myRootElementClass, tag, this, myRootTagName);
60 myRootValue = (T)myManager.createDomElement(myRootElementClass, tag, handler);
62 return myRootValue;
66 void invalidateRoot() {
67 synchronized (PsiLock.LOCK) {
68 myRootValue = null;
72 public String toString() {
73 return "File " + myFile.toString();
76 public XmlTag getXmlTag() {
77 return null;
80 @NotNull
81 public DomFileElementImpl getRoot() {
82 return this;
85 public DomElement getParent() {
86 return null;
89 public XmlTag ensureTagExists() {
90 return null;
93 public void undefine() {
96 public boolean isValid() {
97 return true;
100 public MethodsMap getMethodsMap() {
101 return null;