KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webharvest > definition > BaseElementDef


1 /* Copyright (c) 2006-2007, Vladimir Nikic
2     All rights reserved.
3
4     Redistribution and use of this software in source and binary forms,
5     with or without modification, are permitted provided that the following
6     conditions are met:
7
8     * Redistributions of source code must retain the above
9       copyright notice, this list of conditions and the
10       following disclaimer.
11
12     * Redistributions in binary form must reproduce the above
13       copyright notice, this list of conditions and the
14       following disclaimer in the documentation and/or other
15       materials provided with the distribution.
16
17     * The name of Web-Harvest may not be used to endorse or promote
18       products derived from this software without specific prior
19       written permission.
20
21     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31     POSSIBILITY OF SUCH DAMAGE.
32
33     You can contact Vladimir Nikic by sending e-mail to
34     nikic_vladimir@yahoo.com. Please include the word "Web-Harvest" in the
35     subject line.
36 */

37 package org.webharvest.definition;
38
39 import java.util.*;
40
41 public class BaseElementDef implements IElementDef {
42
43     // sequence of operation definitions
44
List operationDefs = new ArrayList();
45
46     // text content if no nested operation definitions
47
String JavaDoc body;
48
49     // element ID
50
String JavaDoc id;
51
52     protected BaseElementDef() {
53     }
54     
55     protected BaseElementDef(XmlNode node) {
56         this(node, true);
57     }
58
59     protected BaseElementDef(XmlNode node, boolean createBodyDefs) {
60         if (node != null) {
61             this.id = (String JavaDoc) node.get("id");
62
63             List elementList = node.getElementList();
64
65             if (createBodyDefs) {
66                 if (elementList != null && elementList.size() > 0) {
67                     Iterator it = elementList.iterator();
68                     while (it.hasNext()) {
69                         Object JavaDoc element = it.next();
70                         if (element instanceof XmlNode) {
71                             XmlNode currElementNode = (XmlNode) element;
72                             IElementDef def = DefinitionResolver.createElementDefinition(currElementNode);
73                             if (def != null) {
74                                 operationDefs.add(def);
75                             }
76                         } else {
77                             operationDefs.add( new ConstantDef(element.toString()) );
78                         }
79                     }
80                 } else {
81                     body = node.getText();
82                 }
83             }
84         }
85     }
86
87     public boolean hasOperations() {
88         return operationDefs != null && operationDefs.size() > 0;
89     }
90
91     public IElementDef[] getOperationDefs() {
92         IElementDef[] defs = new IElementDef[operationDefs.size()];
93         Iterator it = operationDefs.iterator();
94         int index = 0;
95         while (it.hasNext()) {
96             defs[index++] = (IElementDef) it.next();
97         }
98
99         return defs;
100     }
101
102     public String JavaDoc getBodyText() {
103         return body;
104     }
105
106     public String JavaDoc getId() {
107         return id;
108     }
109
110 }
Popular Tags