KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > metadata > ElementEdit


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: ElementEdit.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.metadata;
25
26 import org.enhydra.xml.xmlc.XMLCException;
27 import org.w3c.dom.Document JavaDoc;
28
29 /**
30  * Abstract type used as a base for all element editing definitions. This
31  * provides for the definition of which attributes and elements are to be
32  * operated on by the derived edit definitions.
33  */

34 public abstract class ElementEdit extends MetaDataElement {
35     /**
36      * Attribute names.
37      */

38     private static final String JavaDoc ELEMENT_IDS_ATTR = "elementIds";
39     private static final String JavaDoc ELEMENT_CLASSES_ATTR = "elementClasses";
40     private static final String JavaDoc ELEMENT_TAGS_ATTR = "elementTags";
41
42     /**
43      * Cache of parsed attributes.
44      */

45     private String JavaDoc[] elementIds;
46     private String JavaDoc[] elementClasses;
47     private String JavaDoc[] elementTags;
48
49     /**
50      * Constructor.
51      */

52     public ElementEdit(Document JavaDoc ownerDoc,
53                        String JavaDoc tagName) {
54         super(ownerDoc, tagName);
55     }
56
57     /**
58      * Get the elementIds attribute value.
59      */

60     public String JavaDoc[] getElementIds() {
61         return getStringArrayAttribute(ELEMENT_IDS_ATTR);
62     }
63
64     /**
65      * Set the elementIds attribute value.
66      */

67     public void setElementIds(String JavaDoc[] values) {
68         setRemoveStringArrayAttribute(ELEMENT_IDS_ATTR, values);
69     }
70
71     /**
72      * Add an element ID to the elementIds attribute value.
73      */

74     public void addElementId(String JavaDoc value) {
75         addStringArrayAttribute(ELEMENT_IDS_ATTR, value);
76     }
77
78     /**
79      * Determine if an id matches the element id constraints on
80      * this object. If there are no id constraints, all elements
81      * match. The id maybe null, which only matches if there are
82      * no constraints.
83      */

84     public boolean matchesElementIdConstraints(String JavaDoc id) {
85         if (elementIds == null) {
86             elementIds = getElementIds();
87         }
88         if (elementIds.length == 0) {
89             return true;
90         }
91         if (id == null) {
92             return false;
93         }
94         for (int idx = 0; idx < elementIds.length; idx++) {
95             if (id.equals(elementIds[idx])) {
96                 return true;
97             }
98         }
99         return false;
100     }
101
102     /**
103      * Get the elementClasses attribute value.
104      */

105     public String JavaDoc[] getElementClasses() {
106         return getStringArrayAttribute(ELEMENT_CLASSES_ATTR);
107     }
108
109     /**
110      * Set the elementClasses attribute value.
111      */

112     public void setElementClasses(String JavaDoc[] values) {
113         setRemoveStringArrayAttribute(ELEMENT_CLASSES_ATTR, values);
114     }
115
116     /**
117      * Add a class to the elementClasses attribute value.
118      */

119     public void addElementClass(String JavaDoc value) {
120         addStringArrayAttribute(ELEMENT_CLASSES_ATTR, value);
121     }
122
123     /**
124      * Determine if an element class matches the element class constraints on
125      * this object. If there are no class constraints, all elements match.
126      * The class maybe null, which only matches if there are no constraints.
127      */

128     public boolean matchesElementClassConstraints(String JavaDoc elementClass) {
129         if (elementClasses == null) {
130             elementClasses = getElementClasses();
131         }
132         if (elementClasses.length == 0) {
133             return true;
134         }
135         if (elementClass == null) {
136             return false;
137         }
138         for (int idx = 0; idx < elementClasses.length; idx++) {
139             if (elementClass.equals(elementClasses[idx])) {
140                 return true;
141             }
142         }
143         return false;
144     }
145
146     /**
147      * Get the elementTags attribute value.
148      */

149     public String JavaDoc[] getElementTags() {
150         return getStringArrayAttribute(ELEMENT_TAGS_ATTR);
151     }
152
153     /**
154      * Set the elementTags attribute value.
155      */

156     public void setElementTags(String JavaDoc[] values) {
157         setRemoveStringArrayAttribute(ELEMENT_TAGS_ATTR, values);
158     }
159
160     /**
161      * Add an element to the elementTags attribute value.
162      */

163     public void addElementTag(String JavaDoc value) {
164         addStringArrayAttribute(ELEMENT_TAGS_ATTR, value);
165     }
166
167     /**
168      * Determine if a tag name matches the element tag name constraints on
169      * this object. If there are no tag name constraints, all elements
170      * match.
171      */

172     public boolean matchesElementTagConstraints(String JavaDoc tagName,
173                                                 boolean ignoreCase) {
174         if (elementTags == null) {
175             elementTags = getElementTags();
176         }
177         if (elementTags.length == 0) {
178             return true;
179         }
180         if (ignoreCase) {
181             for (int idx = 0; idx < elementTags.length; idx++) {
182                 if (tagName.equalsIgnoreCase(elementTags[idx])) {
183                     return true;
184                 }
185             }
186         } else {
187             for (int idx = 0; idx < elementTags.length; idx++) {
188                 if (tagName.equals(elementTags[idx])) {
189                     return true;
190                 }
191             }
192         }
193         return false;
194     }
195
196     /**
197      * Complete modifications to DOM. This clears cache of parsed
198      * attributes.
199      */

200     protected void completeModifications() throws XMLCException {
201         super.completeModifications();
202         elementIds = null;
203         elementClasses = null;
204         elementTags = null;
205     }
206 }
207
Popular Tags