IndexedSpacesRegistry.java

src/net/sourceforge/pain/data/IndexedSpacesRegistry.java · 1.2 KB

From the archive pain_0_41.zip

Download the archive   « Back to the archive contents

package net.sourceforge.pain.data;

import net.sourceforge.pain.data.type.*;
import net.sourceforge.pain.db.*;

import java.util.*;

/**
 * PAiN  Date: 14.06.2003  Time: 0:58:00
 */
public final class IndexedSpacesRegistry extends DbObject {
	private static final int SPACE_BY_ID = 0;
	private static final int NFIELDS = 1;

	public IndexedSpacesRegistry() {
	}

	public IndexedSpacesRegistry(PainDB db)  {
		super(db);
	}

	protected DbClassSchema provideSchema() {
		byte types[] = new byte[NFIELDS];
		String names[] = new String[NFIELDS];

		types[SPACE_BY_ID] = DbType.STRING_KEY_MAP;
		names[SPACE_BY_ID] = "named_space_map";

		return new DbClassSchema(types, names);

	}

	public IndexedSpace getSpace(String spaceUniqueId) {
		return (IndexedSpace) getStringKeyMap(SPACE_BY_ID).get(spaceUniqueId);
	}


	public void registerSpace(IndexedSpace space) {
		final Map m = getStringKeyMap(SPACE_BY_ID);
		final String id = space.getSpaceUniqueId();
		if (m.containsKey(id)) {
			throw new RuntimeException("Dublicate  index:" + id);
		}
		m.put(id, space);
	}

	public void unregisterSpace(IndexedSpace space) {
		final Map m = getStringKeyMap(SPACE_BY_ID);
		final String name = space.getSpaceUniqueId();
		m.remove(name);
	}

}

Site Stats

Snippets: 1791
Codebases: 571