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: package org.netbeans.modules.cnd.makeproject.configurations;
043:
044: import org.netbeans.modules.cnd.makeproject.api.configurations.ItemConfiguration;
045: import org.netbeans.modules.cnd.api.xml.AttrValuePair;
046: import org.netbeans.modules.cnd.api.xml.VersionException;
047: import org.netbeans.modules.cnd.api.xml.XMLDecoder;
048: import org.netbeans.modules.cnd.api.xml.XMLEncoder;
049: import org.netbeans.modules.cnd.api.xml.XMLEncoderStream;
050: import org.netbeans.modules.cnd.api.compilers.Tool;
051: import org.xml.sax.Attributes;
052:
053: public class ItemXMLCodec extends XMLDecoder implements XMLEncoder {
054:
055: private ItemConfiguration item;
056:
057: public final static String ITEM_ELEMENT = "item"; // NOI18N
058: public final static String PATH_ATTR = "path"; // NOI18N
059: public final static String EXCLUDED_ELEMENT = "excluded"; // FIXUP: < 7 // NOI18N
060: public final static String TOOL_ELEMENT = "tool"; // FIXUP: < 7 // NOI18N
061: public final static String ITEM_EXCLUDED_ELEMENT = "itemExcluded"; // NOI18N
062: public final static String ITEM_TOOL_ELEMENT = "itemTool"; // NOI18N
063: public final static String DEBUGGING_ELEMENT = "justfordebugging"; // NOI18N
064:
065: public final static String TRUE_VALUE = "true"; // NOI18N
066: public final static String FALSE_VALUE = "false"; // NOI18N
067:
068: public ItemXMLCodec(ItemConfiguration item) {
069: this .item = item;
070: }
071:
072: // interface XMLDecoder
073: public String tag() {
074: return item.getId();
075: }
076:
077: // interface XMLDecoder
078: public void start(Attributes atts) throws VersionException {
079: String what = "item"; // NOI18N
080: int maxVersion = 1;
081: checkVersion(atts, what, maxVersion);
082: }
083:
084: // interface XMLDecoder
085: public void end() {
086: }
087:
088: // interface XMLDecoder
089: public void startElement(String element, Attributes atts) {
090: }
091:
092: // interface XMLDecoder
093: public void endElement(String element, String currentText) {
094: }
095:
096: // interface XMLEncoder
097: public void encode(XMLEncoderStream xes) {
098: xes.elementOpen(ITEM_ELEMENT,
099: new AttrValuePair[] { new AttrValuePair(PATH_ATTR, item
100: .getItem().getPath()) });
101: if (item.getExcluded().getModified())
102: xes.element(ITEM_EXCLUDED_ELEMENT, ""
103: + item.getExcluded().getValue()); // NOI18N
104: xes.element(ITEM_TOOL_ELEMENT, "" + item.getTool()); // NOI18N
105: if (item.getTool() == Tool.CCompiler) {
106: CommonConfigurationXMLCodec.writeCCompilerConfiguration(
107: xes, item.getCCompilerConfiguration());
108: } else if (item.getTool() == Tool.CCCompiler) {
109: CommonConfigurationXMLCodec.writeCCCompilerConfiguration(
110: xes, item.getCCCompilerConfiguration());
111: } else if (item.getTool() == Tool.FortranCompiler) {
112: CommonConfigurationXMLCodec
113: .writeFortranCompilerConfiguration(xes, item
114: .getFortranCompilerConfiguration());
115: } else if (item.getTool() == Tool.CustomTool) {
116: CommonConfigurationXMLCodec.writeCustomToolConfiguration(
117: xes, item.getCustomToolConfiguration());
118: }
119: xes.elementClose(ITEM_ELEMENT);
120: }
121: }
|