KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > ExtensionElementDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.util.*;
26
27 /**
28  * This class contains the deployment extensions element for a particular
29  * xml node. It can contains sub elements (other ExtensionElementDescriptor
30  * instances) or final leafs like attribute or string elements.
31  *
32  * @author Jerome Dochez
33  */

34 public class ExtensionElementDescriptor extends Descriptor implements Observer {
35     
36     private List elementNames;
37     private Map elementValues;
38     private DynamicAttributesDescriptor attributes;
39     
40     /**
41      * @return the value holder for all sub elements of
42      * this deployment extension element
43      */

44     public Iterator getElementNames() {
45         if (elementNames!=null) {
46             return elementNames.iterator();
47         }
48         return null;
49     }
50     
51     public void addElement(String JavaDoc elementName, Object JavaDoc value) {
52         if (elementNames==null) {
53             elementNames = new LinkedList();
54             elementValues = new HashMap();
55         }
56         elementNames.add(elementName);
57         elementValues.put(elementName, value);
58         changed();
59     }
60     
61     public Object JavaDoc getElement(String JavaDoc elementName) {
62         if (elementValues!=null) {
63             return elementValues.get(elementName);
64         }
65         return null;
66     }
67     
68     /**
69      * @return a value holder for all attributes of
70      * this deployment extension elements
71      */

72     public DynamicAttributesDescriptor getAttributes() {
73         if (attributes==null) {
74             attributes = new DynamicAttributesDescriptor();
75             attributes.addObserver(this);
76         }
77         return attributes;
78     }
79     
80     /**
81      * @return true if the deployment extension contains attributes
82      */

83     public boolean hasAttributes() {
84         return attributes!=null;
85     }
86     
87     /**
88      * notification of changed from our attributes/elements
89      * storage
90      */

91     public void update(Observable o, Object JavaDoc arg) {
92         setChanged();
93         notifyObservers();
94     }
95     
96     /**
97      * @return a meaningful string describing myself
98      */

99     public void print(StringBuffer JavaDoc toStringBuffer) {
100         toStringBuffer.append("ExtensionElementDescriptor");
101         toStringBuffer.append("\n");
102         super.print(toStringBuffer);
103         for (Iterator itr = getElementNames();itr.hasNext();) {
104             toStringBuffer.append("\n Element=").append(getElement((String JavaDoc) itr.next()));
105         }
106         if (hasAttributes()) {
107             toStringBuffer.append("\n Attributes = ").append(getAttributes());
108         }
109     }
110 }
111
Popular Tags