KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > repository > J2EEResourceBase


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.repository;
24
25 import java.util.*;
26 import java.io.Serializable JavaDoc;
27
28 /**
29  * Base class for common J2EEResource implementation.
30  *
31  * @author
32  */

33 public abstract class J2EEResourceBase implements J2EEResource, Serializable JavaDoc {
34
35     String JavaDoc name_;
36     Map properties_;
37     // START OF IASRI #4626188
38
boolean enabled_;
39     String JavaDoc description_;
40     // END OF IASRI #4626188
41

42     public J2EEResourceBase(String JavaDoc name) {
43         name_ = name;
44         properties_ = new HashMap();
45     }
46
47     public String JavaDoc getName() {
48         return name_;
49     }
50
51     // START OF IASRI #4626188
52
public void setEnabled(boolean value) {
53         enabled_ = value;
54     }
55     
56     public boolean isEnabled() {
57         return enabled_;
58     }
59     
60     public void setDescription(String JavaDoc value) {
61         description_ = value;
62     }
63     
64     public String JavaDoc getDescription() {
65         return description_;
66     }
67     // END OF IASRI #4626188
68

69     public abstract int getType();
70
71     public Set getProperties() {
72         Set shallowCopy = new HashSet();
73         Collection collection = properties_.values();
74         for(Iterator iter = collection.iterator(); iter.hasNext();) {
75             ResourceProperty next = (ResourceProperty) iter.next();
76             shallowCopy.add(next);
77         }
78         return shallowCopy;
79     }
80     
81     public void addProperty(ResourceProperty property) {
82         properties_.put(property.getName(), property);
83     }
84
85     public boolean removeProperty(ResourceProperty property) {
86         Object JavaDoc removedObj = properties_.remove(property.getName());
87         return (removedObj != null);
88     }
89
90     public ResourceProperty getProperty(String JavaDoc propertyName) {
91         return (ResourceProperty) properties_.get(propertyName);
92     }
93
94     public J2EEResource makeClone(String JavaDoc name) {
95         J2EEResource clone = doClone(name);
96         Set entrySet = properties_.entrySet();
97         for(Iterator iter = entrySet.iterator(); iter.hasNext();) {
98             Map.Entry next = (Map.Entry) iter.next();
99             ResourceProperty nextProp = (ResourceProperty) next.getValue();
100             ResourceProperty propClone =
101                 new ResourcePropertyImpl((String JavaDoc) next.getKey());
102             propClone.setValue(next.getValue());
103                                          
104             clone.addProperty(propClone);
105         }
106         // START OF IASRI #4626188
107
clone.setEnabled(isEnabled());
108         clone.setDescription(getDescription());
109         // END OF IASRI #4626188
110
return clone;
111     }
112
113     protected String JavaDoc getPropsString() {
114         StringBuffer JavaDoc propsBuffer = new StringBuffer JavaDoc();
115         Set props = getProperties();
116         if( !props.isEmpty() ) {
117             for(Iterator iter = props.iterator(); iter.hasNext(); ) {
118                 if( propsBuffer.length() == 0 ) {
119                     propsBuffer.append("[ ");
120                 } else {
121                     propsBuffer.append(" , ");
122                 }
123                 ResourceProperty next = (ResourceProperty) iter.next();
124                 propsBuffer.append(next.getName() + "=" + next.getValue());
125             }
126             propsBuffer.append(" ]");
127         }
128         return propsBuffer.toString();
129     }
130
131     protected abstract J2EEResource doClone(String JavaDoc name);
132 }
133
Popular Tags