001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.tax;
042:
043: import org.netbeans.tax.spec.DTD;
044: import org.netbeans.tax.spec.ParameterEntityReference;
045: import org.netbeans.tax.spec.ConditionalSection;
046:
047: /**
048: *
049: * @author Libor Kramolis
050: * @version 0.1
051: */
052: public class TreeConditionalSection extends AbstractTreeDTD implements
053: DTD.Child, ParameterEntityReference.Child,
054: ConditionalSection.Child {
055:
056: /** */
057: public static final String PROP_INCLUDE = "include"; // NOI18N
058: /** */
059: public static final String PROP_IGNORED_CONTENT = "ignoredContent"; // NOI18N
060:
061: /** */
062: public static final boolean IGNORE = false;
063:
064: /** */
065: public static final boolean INCLUDE = true;
066:
067: /** */
068: private boolean include;
069:
070: /** -- can be null. */
071: private String ignoredContent; //or null
072:
073: //
074: // init
075: //
076:
077: /** Creates new TreeConditionalSection. */
078: public TreeConditionalSection(boolean include) {
079: super ();
080:
081: this .include = include;
082: this .ignoredContent = new String();
083: }
084:
085: /** Creates new TreeConditionalSection -- copy constructor. */
086: protected TreeConditionalSection(
087: TreeConditionalSection conditionalSection, boolean deep) {
088: super (conditionalSection, deep);
089:
090: this .include = conditionalSection.include;
091: this .ignoredContent = conditionalSection.ignoredContent;
092: }
093:
094: //
095: // from TreeObject
096: //
097:
098: /**
099: */
100: public Object clone(boolean deep) {
101: return new TreeConditionalSection(this , deep);
102: }
103:
104: /**
105: */
106: public boolean equals(Object object, boolean deep) {
107: if (!!!super .equals(object, deep))
108: return false;
109:
110: TreeConditionalSection peer = (TreeConditionalSection) object;
111: if (this .include != peer.include)
112: return false;
113: if (!!!Util.equals(this .getIgnoredContent(), peer
114: .getIgnoredContent()))
115: return false;
116:
117: return true;
118: }
119:
120: /*
121: * Merges following properties: ignored, ignoredContent.
122: */
123: public void merge(TreeObject treeObject)
124: throws CannotMergeException {
125: super .merge(treeObject);
126:
127: TreeConditionalSection peer = (TreeConditionalSection) treeObject;
128:
129: setIncludeImpl(peer.isInclude());
130: setIgnoredContentImpl(peer.getIgnoredContent());
131: }
132:
133: //
134: // itself
135: //
136:
137: /**
138: */
139: public final boolean isInclude() {
140: return include;
141: }
142:
143: /**
144: */
145: private final void setIncludeImpl(boolean newInclude) {
146: if (Util.THIS.isLoggable()) /* then */
147: Util.THIS
148: .debug("\nTreeConditionalSection::setIncludeImpl: oldInclude = "
149: + this .include); // NOI18N
150: if (Util.THIS.isLoggable()) /* then */
151: Util.THIS
152: .debug(" ::setIncludeImpl: newInclude = "
153: + newInclude); // NOI18N
154:
155: boolean oldInclude = this .include;
156:
157: this .include = newInclude;
158:
159: firePropertyChange(PROP_INCLUDE, oldInclude ? Boolean.TRUE
160: : Boolean.FALSE, newInclude ? Boolean.TRUE
161: : Boolean.FALSE);
162: }
163:
164: /**
165: * @throws ReadOnlyException
166: * @throws InvalidArgumentException
167: */
168: public final void setInclude(boolean newInclude)
169: throws ReadOnlyException, InvalidArgumentException {
170: if (Util.THIS.isLoggable()) /* then */
171: Util.THIS
172: .debug("\nTreeConditionalSection::setInclude: oldInclude = "
173: + this .include); // NOI18N
174: if (Util.THIS.isLoggable()) /* then */
175: Util.THIS
176: .debug(" ::setInclude: newInclude = "
177: + newInclude); // NOI18N
178:
179: //
180: // check new value
181: //
182: if (this .include == newInclude)
183: return;
184: checkReadOnly();
185: // checkInclude (newInclude);
186:
187: //
188: // set new value
189: //
190: setIncludeImpl(newInclude);
191: }
192:
193: /**
194: */
195: public final String getIgnoredContent() {
196: return ignoredContent;
197: }
198:
199: /**
200: */
201: private void setIgnoredContentImpl(String newContent) {
202: String oldContent = this .ignoredContent;
203:
204: this .ignoredContent = newContent;
205:
206: firePropertyChange(PROP_IGNORED_CONTENT, oldContent, newContent);
207: }
208:
209: /**
210: * @throws ReadOnlyException
211: * @throws InvalidArgumentException
212: */
213: public final void setIgnoredContent(String newIgnoredContent)
214: throws ReadOnlyException, InvalidArgumentException {
215: //
216: // check new value
217: //
218: if (Util.equals(this .ignoredContent, newIgnoredContent))
219: return;
220: checkReadOnly();
221: // checkIgnoredContent (newIgnoredContent);
222:
223: //
224: // set new value
225: //
226: setIgnoredContentImpl(newIgnoredContent);
227: }
228:
229: //
230: // TreeObjectList.ContentManager
231: //
232:
233: /**
234: */
235: protected TreeObjectList.ContentManager createChildListContentManager() {
236: return new ChildListContentManager();
237: }
238:
239: /**
240: *
241: */
242: protected class ChildListContentManager extends
243: AbstractTreeDTD.ChildListContentManager {
244:
245: /**
246: */
247: public TreeNode getOwnerNode() {
248: return TreeConditionalSection.this ;
249: }
250:
251: /**
252: */
253: public void checkAssignableObject(Object obj) {
254: super .checkAssignableObject(obj);
255: checkAssignableClass(ConditionalSection.Child.class, obj);
256: }
257:
258: } // end: class ChildListContentManager
259:
260: }
|