View Javadoc

1   /*
2    * $Id: CollectionAdapter.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.xslt;
19  
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.List;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.w3c.dom.Node;
27  
28  
29  /***
30   */
31  public class CollectionAdapter extends AbstractAdapterElement {
32  
33      private Log log = LogFactory.getLog(this.getClass());
34  
35  	public CollectionAdapter() { }
36  
37  	public CollectionAdapter(AdapterFactory rootAdapterFactory, AdapterNode parent, String propertyName, Object value) {
38          setContext(rootAdapterFactory, parent, propertyName, value);
39      }
40  
41      protected List<Node> buildChildAdapters() {
42          Collection values = (Collection) getPropertyValue();
43          List<Node> children = new ArrayList<Node>(values.size());
44  
45          for (Object value : values) {
46              Node childAdapter = getAdapterFactory().adaptNode(this, "item", value);
47              if (childAdapter != null)
48                  children.add(childAdapter);
49  
50              if (log.isDebugEnabled()) {
51                  log.debug(this + " adding adapter: " + childAdapter);
52              }
53          }
54  
55          return children;
56      }
57  }