3434import org .w3c .dom .Document ;
3535import org .w3c .dom .Element ;
3636import org .w3c .dom .Node ;
37+
3738/*
3839 * Base class for UA model elements.
3940 */
@@ -59,6 +60,7 @@ public Filter(String name, String value, boolean isNegated) {
5960 this .value = value ;
6061 this .isNegated = isNegated ;
6162 }
63+
6264 String name ;
6365 String value ;
6466 boolean isNegated ;
@@ -81,8 +83,13 @@ public UAElement(String name, IUAElement src) {
8183 }
8284 }
8385
86+ public UAElement (UAElement src ) {
87+ this (src .getElementName ());
88+ copyFilters (src );
89+ }
90+
8491 private void copyFilters (IUAElement src ) {
85- UAElement sourceElement = (UAElement )src ;
92+ UAElement sourceElement = (UAElement ) src ;
8693 String filter = sourceElement .getAttribute (ATTRIBUTE_FILTER );
8794 if (filter != null && filter .length () > 0 ) {
8895 this .setAttribute (ATTRIBUTE_FILTER , filter );
@@ -101,15 +108,14 @@ private Filter[] getFilterElements() {
101108 if (node .getNodeType () == Node .ELEMENT_NODE ) {
102109 String elementKind = node .getNodeName ();
103110 if (ExpressionTagNames .ENABLEMENT .equals (elementKind )) {
104- Element enablement = (Element )node ;
111+ Element enablement = (Element ) node ;
105112 try {
106113 enablementExpression = ExpressionConverter .getDefault ().perform (enablement );
107- }
108- catch (CoreException e ) {
114+ } catch (CoreException e ) {
109115
110116 }
111117 } else if (ELEMENT_FILTER .equals (elementKind )) {
112- Element filter = (Element )node ;
118+ Element filter = (Element ) node ;
113119 String filterName = filter .getAttribute (ATTRIBUTE_NAME );
114120 String value = filter .getAttribute (ATTRIBUTE_VALUE );
115121 if (filterName .length () > 0 && value .length () > 0 ) {
@@ -146,14 +152,15 @@ public void appendChildren(IUAElement[] children) {
146152 if (this .children == null && children .length > 0 ) {
147153 this .children = new ArrayList <>(4 );
148154 }
149- for (int i = 0 ; i < children . length ; i ++ ) {
150- appendChild (children [ i ] instanceof UAElement ? (UAElement )children [ i ] : UAElementFactory .newElement (children [ i ] ));
155+ for (IUAElement child : children ) {
156+ appendChild (child instanceof UAElement ? (UAElement ) child : UAElementFactory .newElement (child ));
151157 }
152158 }
153159
154160 /*
155- * This method is synchronized to fix Bug 232169. When modifying this source be careful not
156- * to introduce any logic which could possibly cause this thread to block.
161+ * This method is synchronized to fix Bug 232169. When modifying this source
162+ * be careful not to introduce any logic which could possibly cause this
163+ * thread to block.
157164 */
158165 synchronized public String getAttribute (String name ) {
159166 String value = element .getAttribute (name );
@@ -164,9 +171,10 @@ synchronized public String getAttribute(String name) {
164171 }
165172
166173 /*
167- * This method is synchronized to fix Bug 230037. A review of the code indicated that there was no
168- * path which could get blocked and cause deadlock. When modifying this source be careful not
169- * to introduce any logic which could possibly cause this thread to block.
174+ * This method is synchronized to fix Bug 230037. A review of the code
175+ * indicated that there was no path which could get blocked and cause
176+ * deadlock. When modifying this source be careful not to introduce any
177+ * logic which could possibly cause this thread to block.
170178 */
171179 @ Override
172180 public synchronized IUAElement [] getChildren () {
@@ -176,7 +184,7 @@ public synchronized IUAElement[] getChildren() {
176184 Node node = element .getFirstChild ();
177185 while (node != null ) {
178186 if (node .getNodeType () == Node .ELEMENT_NODE ) {
179- UAElement uaElement = UAElementFactory .newElement ((Element )node );
187+ UAElement uaElement = UAElementFactory .newElement ((Element ) node );
180188 if (uaElement != null ) {
181189 uaElement .parent = this ;
182190 children .add (uaElement );
@@ -196,8 +204,7 @@ public <T> T[] getChildren(Class<T> clazz) {
196204 IUAElement [] children = getChildren ();
197205 if (children .length > 0 ) {
198206 List <Object > list = new ArrayList <>();
199- for (int i =0 ;i <children .length ;++i ) {
200- IUAElement child = children [i ];
207+ for (IUAElement child : children ) {
201208 if (clazz .isAssignableFrom (child .getClass ())) {
202209 list .add (child );
203210 }
@@ -256,8 +263,8 @@ public boolean isEnabled(IEvaluationContext context) {
256263 return isEnabledByFilterAttribute (filter );
257264 }
258265 Filter [] filterElements = getFilterElements ();
259- for (int i = 0 ; i < filterElements . length ; i ++ ) {
260- if (!isFilterEnabled (filterElements [ i ] )) {
266+ for (Filter filterElement : filterElements ) {
267+ if (!isFilterEnabled (filterElement )) {
261268 return false ;
262269 }
263270 }
@@ -291,12 +298,12 @@ public void setAttribute(String name, String value) {
291298 private void importElement (UAElement uaElementToImport ) {
292299 Element elementToImport = uaElementToImport .element ;
293300 Document ownerDocument = element .getOwnerDocument ();
294- if (!ownerDocument .equals (elementToImport .getOwnerDocument ()) ) {
295- elementToImport = (Element )ownerDocument .importNode (elementToImport , true );
301+ if (!ownerDocument .equals (elementToImport .getOwnerDocument ())) {
302+ elementToImport = (Element ) ownerDocument .importNode (elementToImport , true );
296303 uaElementToImport .children = null ;
297- } else {
304+ } else {
298305 if (elementToImport .getParentNode () != null ) {
299- elementToImport = (Element )ownerDocument .importNode (elementToImport , true );
306+ elementToImport = (Element ) ownerDocument .importNode (elementToImport , true );
300307 uaElementToImport .children = null ;
301308 } else {
302309 }
0 commit comments