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-2007 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:
042: /*
043: * File : LiteralInfo.java
044: * Version : 1.0
045: * Description : Information about the changes to an enumeration's literal.
046: * Author : Daniel Prusa
047: */
048: package org.netbeans.modules.uml.integration.ide.events;
049:
050: import java.lang.reflect.Modifier;
051: import java.util.StringTokenizer;
052: import org.netbeans.modules.uml.core.metamodel.core.constructs.IEnumeration;
053: import org.netbeans.modules.uml.core.metamodel.core.constructs.IEnumerationLiteral;
054: import org.netbeans.modules.uml.integration.ide.ChangeUtils;
055: import org.netbeans.modules.uml.integration.ide.JavaClassUtils;
056: import org.netbeans.modules.uml.integration.ide.UMLSupport;
057: import org.netbeans.modules.uml.core.support.umlsupport.Log;
058: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
059: import org.netbeans.modules.uml.core.metamodel.core.foundation.IMultiplicity;
060: import org.netbeans.modules.uml.core.metamodel.core.foundation.IMultiplicityRange;
061: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
062: import org.netbeans.modules.uml.core.metamodel.structure.IProject;
063: import org.netbeans.modules.uml.core.support.umlutils.ETList;
064:
065: public class LiteralInfo extends ElementInfo {
066: /** The containing class information. */
067: private ClassInfo mContainer = null;
068:
069: /**
070: * The IEnumerationLiteral from which this LiteralInfo was constructed. If the
071: * LiteralInfo was constructed by an IDE integration, this should be null.
072: */
073: private IEnumerationLiteral literal = null;
074:
075: public IEnumerationLiteral getLiteral() {
076: return literal;
077: }
078:
079: public LiteralInfo(ClassInfo container, int type) {
080: super (type);
081: setContainingClass(container);
082: }
083:
084: public LiteralInfo(ClassInfo container, IEnumerationLiteral literal) {
085: super (literal);
086: setContainingClass(container);
087:
088: this .literal = literal;
089: setFromLiteral(literal);
090: }
091:
092: public LiteralInfo(IEnumerationLiteral lit) {
093: this (null, lit);
094: }
095:
096: /* (non-Javadoc)
097: * @see com.embarcadero.integration.events.ElementInfo#getOwningProject()
098: */
099: public IProject getOwningProject() {
100: return literal != null ? (IProject) literal.getProject()
101: : getContainingClass() != null ? getContainingClass()
102: .getOwningProject() : null;
103: }
104:
105: public String getFilename() {
106: return (mContainer != null ? mContainer.getFilename() : null);
107: }
108:
109: public IProject getProject() {
110: return literal != null ? (IProject) literal.getProject() : null;
111: }
112:
113: /**
114: * Set all properties for this LiteralInfo using info from the given
115: * IEnumerationLiteral.
116: * @param attr An <code>IEnumerationLiteral</code> for the literal.
117: */
118: public void setFromLiteral(IEnumerationLiteral lit) {
119: setName(lit.getName());
120: // Assuming the container hasn't been set, attempt to create a
121: // ClassInfo for it.
122: if (getContainingClass() == null) {
123: IEnumeration owner = lit.getEnumeration();
124: ClassInfo inf = ClassInfo.getRefClassInfo(owner, true);
125: setContainingClass(inf);
126: }
127: }
128:
129: /**
130: * Retrieves the containing clas of the data member.
131: * @return The containing class.
132: */
133: public ClassInfo getContainingClass() {
134: return mContainer;
135: }
136:
137: /**
138: * Sets the containing clas of the data member.
139: * @param container The containing class.
140: */
141: public void setContainingClass(ClassInfo container) {
142: mContainer = container;
143: }
144:
145: public void update() {
146: if (getContainingClass() != null) {
147: SymbolTransaction trans = new SymbolTransaction(
148: getContainingClass());
149: update(trans);
150: }
151: }
152:
153: public LiteralTransaction update(SymbolTransaction trans) {
154: EventManager manager = EventManager.getEventManager();
155:
156: LiteralTransaction retVal = new LiteralTransaction(trans, this );
157: IEnumerationLiteral lit = retVal.getLiteral();
158:
159: if (lit == null)
160: return null;
161:
162: manager.getEventFilter().blockEventType(
163: ChangeUtils.RDT_DEPENDENCY_ADDED);
164: try {
165: if (retVal != null) {
166: if (getChangeType() == ElementInfo.DELETE) {
167: lit.delete();
168: } else {
169: if (getNewName() != null) {
170: lit.setName(getNewName());
171: }
172: }
173: }
174: } finally {
175: manager.getEventFilter().unblockEventType(
176: ChangeUtils.RDT_DEPENDENCY_ADDED);
177: }
178:
179: return retVal;
180: }
181:
182: public String getCode() {
183: return "L";
184: }
185:
186: public String toString() {
187: StringBuffer str = new StringBuffer("" + getName());
188: return str.toString();
189: }
190:
191: }
|