View Javadoc

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