KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > jmiimpl > javamodel > TagValueImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.javacore.jmiimpl.javamodel;
20
21 import org.netbeans.jmi.javamodel.Element;
22 import org.netbeans.jmi.javamodel.JavaModelPackage;
23 import org.netbeans.jmi.javamodel.TagDefinition;
24 import org.netbeans.jmi.javamodel.TagValue;
25 import org.netbeans.mdr.storagemodel.StorableObject;
26 import org.netbeans.modules.javacore.parser.MDRParser;
27
28 /**
29  * Implementation of TagValue object instance interface.
30  *
31  * @author Vladimir Hudec
32  */

33 public abstract class TagValueImpl extends MetadataElement implements TagValue {
34
35     protected String JavaDoc value = null;
36     protected TagDefinition tagDefinition = null;
37     
38     private boolean isNew = false;
39     protected boolean childrenInited = false;
40     
41     
42     protected TagValueImpl(StorableObject s) {
43         super(s);
44     }
45     
46     protected final boolean isInitialized() {
47         return isNew;
48     }
49     
50     /** Overriding methods must call super.setNew() */
51     protected void setNew() {
52         setChanged();
53         isNew = true;
54         childrenInited = true;
55     }
56     
57     protected final boolean isNew() {
58         return isNew;
59     }
60  
61     /**
62      * Returns the value of attribute value.
63      * @return Value of attribute value.
64      */

65     public String JavaDoc getValue() {
66         return value;
67     }
68     
69     /**
70      * Sets the value of value attribute. See {@link #getValue} for description
71      * on the attribute.
72      * @param newValue New value to be set.
73      */

74     public void setValue(String JavaDoc newValue) {
75         objectChanged(CHANGED_JAVADOC);
76         this.value = newValue;
77     }
78     
79     /**
80      * Returns the value of reference definition.
81      * @return Value of reference definition.
82      */

83     public TagDefinition getDefinition() {
84         return tagDefinition;
85     }
86     
87     /**
88      * Sets the value of reference definition. See {@link #getDefinition} for
89      * description on the reference.
90      * @param newValue New value to be set.
91      */

92     public void setDefinition(TagDefinition newValue) {
93         if (tagDefinition != null && newValue != null && tagDefinition.equals(newValue))
94             return;
95
96         IsValueForImpl isValueForImpl = (IsValueForImpl)(((JavaModelPackage) refImmediatePackage()).getIsValueFor());
97
98         if (tagDefinition != null)
99             isValueForImpl.remove(this, tagDefinition);
100         if (newValue != null)
101             isValueForImpl.add(this, newValue);
102     }
103     
104     void setData(String JavaDoc name, String JavaDoc value) {
105         if (name != null) {
106             JavaModelPackage pkg = (JavaModelPackage) refImmediatePackage();
107             TagDefinitionClassImpl tagDefinitionClass = (TagDefinitionClassImpl) pkg.getTagDefinition();
108             setData(value, tagDefinitionClass.createTagDefinition(name));
109         }
110         else {
111             setData(value, (TagDefinition)null);
112         }
113     }
114
115     void setData(String JavaDoc value, TagDefinition tagDefinition) {
116         this.value = value;
117         this.tagDefinition = tagDefinition;
118     }
119     
120     protected java.lang.Object JavaDoc getInternalForm() {
121         return value;
122     }
123     
124     public MDRParser getParser() {
125         return null;
126     }
127     
128     public Element duplicate(JavaModelPackage targetExtent) {
129         TagValueClassImpl tagProxy = (TagValueClassImpl)targetExtent.getTagValue();
130         String JavaDoc name = null;
131         TagDefinition def = getDefinition();
132         
133         if (def != null)
134             name = def.getName();
135         return tagProxy.create(name,getValue());
136     }
137 }
138
Popular Tags