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.modelimpl.cache.impl;
043:
044: import java.io.IOException;
045: import java.io.ObjectInputStream;
046: import java.io.ObjectOutputStream;
047: import java.io.Serializable;
048: import org.netbeans.modules.cnd.api.model.CsmProject;
049: import org.netbeans.modules.cnd.modelimpl.csm.core.ProjectBase;
050:
051: /** implementation of master index file
052: * it's responsibility to make pair for project and it's cache dir
053: * (project cache dir is relative to main cndcache directory)
054: *
055: * @author Vladimir Voskresensky
056: */
057: final class MasterIndex extends AbstractCacheIndex implements
058: Serializable {
059: private static final long serialVersionUID = -7790789617759717722L;
060:
061: // Map has structure <absolute-project-path, project-relative-cache-dir>
062:
063: public MasterIndex() {
064: }
065:
066: public String getProjectDir(CsmProject project) {
067: return (String) super .get(project);
068: }
069:
070: public String putProject(CsmProject project) {
071: return (String) super .put(project);
072: }
073:
074: ////////////////////////////////////////////////////////////////////////////
075: // save/load implmentation
076:
077: @Override
078: protected void loadData(ObjectInputStream ois) throws IOException,
079: ClassNotFoundException {
080: int version = ois.readInt();
081: if (version >= 1) {
082: // version 1
083: // - load base data
084: super .loadData(ois);
085: }
086: }
087:
088: @Override
089: protected void saveData(ObjectOutputStream oos) throws IOException {
090: int version = 1;
091: oos.writeInt(version);
092:
093: // version 1
094: // - save base data
095: super .saveData(oos);
096: }
097:
098: ////////////////////////////////////////////////////////////////////////////
099: // index map content support
100:
101: protected String getIndexKey(Object obj) {
102: return ((ProjectBase) obj).getUniqueName().toString();
103: }
104:
105: protected String getBaseCacheName(Object obj) {
106: // use directory name for the project
107: CsmProject project = (CsmProject) obj;
108: String base = CacheUtil.mangleName(project.getName(), '_');
109: return base;
110: }
111:
112: protected Object createValue(CharSequence cacheName,
113: Object obj2cache) {
114: return cacheName;
115: }
116:
117: protected boolean isEqual(Object value, CharSequence checkCacheName) {
118: return ((String) value).equals(checkCacheName);
119: }
120: }
|