001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.launching;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.debug.core.ILaunchConfiguration;
014: import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
015: import org.w3c.dom.Document;
016: import org.w3c.dom.Element;
017:
018: /**
019: * Specialization for a String variable classpath entry
020: */
021: public class VariableClasspathEntry extends
022: AbstractRuntimeClasspathEntry {
023: public static final String TYPE_ID = "org.eclipse.jdt.launching.classpathentry.variableClasspathEntry"; //$NON-NLS-1$
024: private String variableString;
025:
026: /**
027: * Constructor
028: */
029: public VariableClasspathEntry() {
030: }
031:
032: /**
033: * Constructor
034: * @param variableString
035: */
036: public VariableClasspathEntry(String variableString) {
037: this .variableString = variableString;
038: }
039:
040: /* (non-Javadoc)
041: * @see org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry#buildMemento(org.w3c.dom.Document, org.w3c.dom.Element)
042: */
043: protected void buildMemento(Document document, Element memento)
044: throws CoreException {
045: memento.setAttribute("variableString", variableString); //$NON-NLS-1$
046: memento.setAttribute(
047: "path", Integer.toString(getClasspathProperty())); //$NON-NLS-1$
048: }
049:
050: /* (non-Javadoc)
051: * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#initializeFrom(org.w3c.dom.Element)
052: */
053: public void initializeFrom(Element memento) throws CoreException {
054: variableString = memento.getAttribute("variableString"); //$NON-NLS-1$
055: String property = memento.getAttribute("path"); //$NON-NLS-1$
056: if (property != null && !"".equals(property)) { //$NON-NLS-1$
057: try {
058: setClasspathProperty(Integer.parseInt(property));
059: } catch (NumberFormatException nfe) {/*do nothing, but don't throw an exception*/
060: }
061: }
062:
063: }
064:
065: /* (non-Javadoc)
066: * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getTypeId()
067: */
068: public String getTypeId() {
069: return TYPE_ID;
070: }
071:
072: /* (non-Javadoc)
073: * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getRuntimeClasspathEntries(org.eclipse.debug.core.ILaunchConfiguration)
074: */
075: public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(
076: ILaunchConfiguration configuration) throws CoreException {
077: return new IRuntimeClasspathEntry[0];
078: }
079:
080: /* (non-Javadoc)
081: * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getName()
082: */
083: public String getName() {
084: return variableString;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getType()
089: */
090: public int getType() {
091: return OTHER;
092: }
093:
094: /**
095: * @return Returns the variableString.
096: */
097: public String getVariableString() {
098: return variableString;
099: }
100:
101: /**
102: * @param variableString The variableString to set.
103: */
104: public void setVariableString(String variableString) {
105: this .variableString = variableString;
106: }
107:
108: /* (non-Javadoc)
109: * @see java.lang.Object#hashCode()
110: */
111: public int hashCode() {
112: if (variableString != null) {
113: return variableString.hashCode();
114: }
115: return 0;
116: }
117:
118: /* (non-Javadoc)
119: * @see java.lang.Object#equals(java.lang.Object)
120: */
121: public boolean equals(Object obj) {
122: if (obj instanceof VariableClasspathEntry) {
123: VariableClasspathEntry other = (VariableClasspathEntry) obj;
124: if (variableString != null) {
125: return variableString.equals(other.variableString);
126: }
127: }
128: return false;
129: }
130: }
|