]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.jemmy/src/main/java/org/argeo/slc/jemmy/AbstractComponentWrapper.java
20d019f446424480239a15634754810f345b1541
2 * Copyright (C) 2007-2012 Mathieu Baudier
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 org
.argeo
.slc
.jemmy
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
25 import org
.netbeans
.jemmy
.operators
.ComponentOperator
;
27 public class AbstractComponentWrapper
implements ComponentWrapper
{
29 protected ComponentWrapper parent
;
32 * List of children ComponentWrapper
34 protected List children
= new ArrayList();
36 protected WrapperLocator locator
;
38 protected String prefix
;
40 public ComponentOperator
find() {
41 return locator
.find(this);
44 protected String
createNewKey(String oldKey
) {
45 return (prefix
== null) ? oldKey
: (prefix
+ "." + oldKey
);
48 protected void addToAccessorMap(Map accessors
, String oldKey
,
50 String newKey
= createNewKey(oldKey
);
51 if (accessors
.containsKey(newKey
)) {
52 throw new ConfigRuntimeException("An Accessor with key '" + newKey
53 + "' was already registered");
55 accessors
.put(newKey
, accessor
);
58 public Map
getAccessors(Class accessorClass
) {
59 Map accessors
= new HashMap();
60 if (accessorClass
.isInstance(this)) {
61 addToAccessorMap(accessors
, ((Accessor
) this).getFieldName(), this);
63 for (int i
= 0; i
< children
.size(); i
++) {
64 Map childAccessors
= ((ComponentWrapper
) children
.get(i
))
65 .getAccessors(accessorClass
);
67 Set entries
= childAccessors
.entrySet();
68 Iterator it
= entries
.iterator();
70 while (it
.hasNext()) {
71 Map
.Entry keyValue
= (Map
.Entry
) it
.next();
72 addToAccessorMap(accessors
, keyValue
.getKey().toString(),
79 public ComponentWrapper
getParent() {
83 public void setParent(ComponentWrapper parent
) {
84 if (this.parent
!= null) {
85 throw new ConfigRuntimeException("Parent already set");
90 public List
getChildren() {
94 public void setChildren(List children
) {
95 this.children
= children
;
97 // check that all elements of the list are ComponentWrapper
98 // and set their parent
99 for (int i
= 0; i
< this.children
.size(); i
++) {
100 ComponentWrapper wrapper
= (ComponentWrapper
) this.children
.get(i
);
101 if (wrapper
== null) {
102 throw new ConfigRuntimeException(
103 "Children of ComponentWrappers must be ComponentWrappers");
105 wrapper
.setParent(this);
109 public WrapperLocator
getLocator() {
113 public void setLocator(WrapperLocator locator
) {
114 this.locator
= locator
;
117 public String
getPrefix() {
121 public void setPrefix(String prefix
) {
122 this.prefix
= prefix
;