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
.openapi
.deployment
;
18 import com
.intellij
.openapi
.module
.Module
;
19 import com
.intellij
.openapi
.util
.InvalidDataException
;
20 import com
.intellij
.openapi
.util
.JDOMExternalizable
;
21 import com
.intellij
.openapi
.util
.WriteExternalException
;
22 import org
.jdom
.Element
;
23 import org
.jetbrains
.annotations
.NonNls
;
24 import org
.jetbrains
.annotations
.NotNull
;
26 import java
.util
.LinkedHashMap
;
27 import java
.util
.List
;
30 public abstract class ContainerElement
implements JDOMExternalizable
, Cloneable
, ResolvableElement
{
31 private final Map
<String
,String
> myAttributes
= new LinkedHashMap
<String
, String
>();
32 private final Module myParentModule
;
33 @NonNls public static final String URI_ATTRIBUTE
= "URI";
34 @NonNls public static final String PACKAGING_METHOD_ATTRIBUTE
= "method";
35 @NonNls public static final String ELEMENT_ATTRIBUTE
= "attribute";
36 @NonNls public static final String ATTRIBUTE_NAME
= "name";
37 @NonNls public static final String ATTRIBUTE_VALUE
= "value";
39 protected ContainerElement(@NotNull Module parentModule
) {
40 myParentModule
= parentModule
;
43 public abstract String
getPresentableName();
45 public String
getURI() {
46 return getAttribute(URI_ATTRIBUTE
);
49 public void setURI(String uri
) {
50 setAttribute(URI_ATTRIBUTE
, uri
);
52 public PackagingMethod
getPackagingMethod() {
53 final String attribute
= getAttribute(PACKAGING_METHOD_ATTRIBUTE
);
54 return attribute
== null ? PackagingMethod
.DO_NOT_PACKAGE
: PackagingMethod
.getDeploymentMethodById(attribute
);
56 public void setPackagingMethod(PackagingMethod method
) {
57 setAttribute(PACKAGING_METHOD_ATTRIBUTE
, method
.getId());
60 public void setAttribute(String name
, String value
) {
61 myAttributes
.put(name
, value
);
63 public String
getAttribute(String name
) {
64 return myAttributes
.get(name
);
68 public Module
getParentModule() {
69 return myParentModule
;
72 public void readExternal(Element element
) throws InvalidDataException
{
73 final List attrs
= element
.getChildren(ELEMENT_ATTRIBUTE
);
74 for (Object attr
: attrs
) {
75 Element attribute
= (Element
)attr
;
76 final String name
= attribute
.getAttributeValue(ATTRIBUTE_NAME
);
77 final String value
= attribute
.getAttributeValue(ATTRIBUTE_VALUE
);
78 setAttribute(name
, value
);
82 public void writeExternal(Element element
) throws WriteExternalException
{
83 for (Object o
: myAttributes
.keySet()) {
84 String name
= (String
)o
;
85 String value
= getAttribute(name
);
86 final Element attr
= new Element(ELEMENT_ATTRIBUTE
);
87 attr
.setAttribute(ATTRIBUTE_NAME
, name
);
88 attr
.setAttribute(ATTRIBUTE_VALUE
, value
== null ?
"" : value
);
89 element
.addContent(attr
);
93 public abstract boolean equalsIgnoreAttributes(ContainerElement otherElement
);
94 public boolean equals(Object o
) {
95 if (this == o
) return true;
96 if (!(o
instanceof ContainerElement
)) return false;
98 final ContainerElement otherElement
= (ContainerElement
)o
;
99 if (!equalsIgnoreAttributes(otherElement
)) return false;
100 return myAttributes
.equals(otherElement
.myAttributes
);
103 public int hashCode() {
107 public ContainerElement
clone() {
108 throw new UnsupportedOperationException();