KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > config > node > link > AbstractLinkNode


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.config.node.link;
19
20 import org.sape.carbon.core.config.format.ConfigurationFormatException;
21 import org.sape.carbon.core.config.node.ConfigurationDocument;
22 import org.sape.carbon.core.config.node.Node;
23 import org.sape.carbon.core.config.node.NodeIOException;
24 import org.sape.carbon.core.config.node.NodeNotFoundException;
25 import org.sape.carbon.core.config.node.NodeRemovalException;
26 import org.sape.carbon.core.exception.InvalidParameterException;
27
28 /**
29  * Base class for <code>LinkNode</code>s. Implements methods in the
30  * <code>Node</code> and <code>LinkNode</code> interfaces. This class is
31  * an aggregation of 2 <code>Node</code>s:
32  * <ul>
33  * <li>A <code>ConfigurationDocument</code> -
34  * contains the configuration of the link, used for the underlying
35  * implementation of the <code>LinkNode</code> interface</li>
36  * <li>A <code>Node</code> -
37  * the target of the link, used as the underlying
38  * implementation of the <code>Node</code> interface.</li>
39  * </ul>
40  *
41  * Copyright 2002 Sapient
42  * @since carbon 1.0
43  * @author Douglas Voet, March 2002
44  * @version $Revision: 1.7 $($Author: dvoet $ / $Date: 2003/10/17 14:40:55 $)
45  */

46 public abstract class AbstractLinkNode implements LinkNode {
47     /**
48      * The <code>ConfigurationDocument</code> containing the link's
49      * configuration.
50      *
51      * @link aggregationByValue
52      */

53     protected ConfigurationDocument linkConfigurationDocument;
54
55     /**
56      * The target <code>Node</code> of this link.
57      *
58      * @link aggregationByValue
59      */

60     protected Node targetNode;
61
62     /**
63      * Constructor
64      *
65      * @param linkConfigurationDocument the configuration of the link
66      * @param targetNode the target of the link
67      *
68      * @throws NullPointerException if linkConfigurationDocument or
69      * targetNode is null
70      */

71     public AbstractLinkNode(
72         ConfigurationDocument linkConfigurationDocument,
73         Node targetNode) {
74
75         if (linkConfigurationDocument == null) {
76             throw new InvalidParameterException(
77                 this.getClass(),
78                 "linkConfigurationDocument cannot be null");
79         }
80         if (targetNode == null) {
81             throw new InvalidParameterException(
82                 this.getClass(),
83                 "targetNode cannot be null");
84         }
85
86         this.linkConfigurationDocument = linkConfigurationDocument;
87
88         this.targetNode = targetNode;
89     }
90
91     /**
92      * @see LinkNode#readLinkConfiguration()
93      */

94     public LinkNodeConfiguration readLinkConfiguration()
95         throws NodeIOException, ConfigurationFormatException {
96
97         return (LinkNodeConfiguration)
98             this.linkConfigurationDocument.readConfiguration();
99     }
100
101     /**
102      * @see LinkNode#readLinkConfiguration
103      */

104     public void writeLinkConfiguration(LinkNodeConfiguration config)
105         throws NodeIOException, ConfigurationFormatException {
106
107         this.linkConfigurationDocument.writeConfiguration(config);
108         config.getLinkNodeFactoryClass();
109     }
110
111     /**
112      * @see Node#getName()
113      */

114     public String JavaDoc getName() {
115         return this.linkConfigurationDocument.getName();
116     }
117
118     /**
119      * @see Node#getAbsoluteName()
120      */

121     public String JavaDoc getAbsoluteName() {
122         return this.linkConfigurationDocument.getAbsoluteName();
123     }
124
125     /**
126      * @see Node#getAllowsChildren()
127      */

128     public boolean getAllowsChildren() {
129         return this.targetNode.getAllowsChildren();
130     }
131
132     /**
133      * @see Node#remove()
134      */

135     public int remove() throws NodeRemovalException {
136         return this.linkConfigurationDocument.remove();
137     }
138
139     /**
140      * @see Node#getParent()
141      */

142     public Node getParent() {
143         return this.linkConfigurationDocument.getParent();
144     }
145
146     /**
147      * Returns the name of the node
148      *
149      * @return the name of the node
150      */

151     public String JavaDoc toString() {
152         return getName();
153     }
154
155     /**
156      * @see Node#isRemoved()
157      */

158     public boolean isRemoved() {
159         return (this.linkConfigurationDocument.isRemoved()
160             || this.targetNode.isRemoved());
161     }
162
163     /**
164      * @see Node#refresh()
165      */

166     public void refresh() {
167         this.targetNode.refresh();
168     }
169
170     /**
171      * @see Node#containsChild(String)
172      */

173     public boolean containsChild(String JavaDoc childName) {
174         return targetNode.containsChild(childName);
175     }
176
177     /**
178      * @see Node#fetchChild(String)
179      */

180     public Node fetchChild(String JavaDoc childName)
181         throws NodeNotFoundException {
182
183         return targetNode.fetchChild(childName);
184     }
185
186     /**
187      * @see Node#fetchChildren()
188      */

189     public Node[] fetchChildren() {
190         return targetNode.fetchChildren();
191     }
192
193 }
194
Popular Tags