![JAR search and dependency download from the Maven repository](/logo.png)
com.sun.electric.technology.TechFactory Maven / Gradle / Ivy
/* -*- tab-width: 4 -*-
*
* Electric(tm) VLSI Design System
*
* File: TechFactory.java
*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
*
* Electric(tm) is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Electric(tm) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Electric(tm); see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, Mass 02111-1307, USA.
*/
package com.sun.electric.technology;
import com.sun.electric.Main;
import com.sun.electric.database.id.IdManager;
import com.sun.electric.database.id.IdReader;
import com.sun.electric.database.id.IdWriter;
import com.sun.electric.database.text.TextUtils;
import com.sun.electric.technology.technologies.Generic;
import com.sun.electric.tool.user.ActivityLogger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
*
*/
public abstract class TechFactory {
final String techName;
private final List techParams;
public static class Param {
public final String xmlPath;
public final String prefPath;
public final Object factoryValue;
public Param(String xmlPath, String prefPath, Object factoryValue) {
this.xmlPath = xmlPath;
this.prefPath = prefPath;
this.factoryValue = factoryValue;
}
@Override
public boolean equals(Object o) {
return o instanceof Param && xmlPath.equals(((Param) o).xmlPath);
}
@Override
public int hashCode() {
return xmlPath.hashCode();
}
@Override
public String toString() {
return xmlPath;
}
}
public static TechFactory fromXml(URL url, Xml.Technology xmlTech) {
String techName = null;
if (xmlTech != null) {
techName = xmlTech.techName;
}
if (techName == null) {
techName = TextUtils.getFileNameWithoutExtension(url);
}
return new FromXml(techName, true, url, xmlTech);
}
public Technology newInstance(Generic generic) {
return newInstance(generic, Collections.emptyMap());
}
public Technology newInstance(Generic generic, Map paramValues) {
try {
Map fixedParamValues = new HashMap();
for (Param param : techParams) {
Object value = paramValues.get(param);
if (value == null || value.getClass() != param.factoryValue.getClass()) {
value = param.factoryValue;
}
fixedParamValues.put(param, value);
}
Technology tech = newInstanceImpl(generic, fixedParamValues);
// make sure the name is unique
// Technology already = Technology.findTechnology(tech.getTechName());
// if (already != null)
// {
// System.out.println("ERROR: Multiple technologies named '" + tech.getTechName() + "'");
// return null;
// }
tech.setup();
return tech;
} catch (ClassNotFoundException e) {
TextUtils.recordMissingTechnology("Extra");
} catch (Exception e) {
System.out.println("Exceptions while importing extra technology " + getDescription());
// if (Job.getDebug())
ActivityLogger.logException(e);
}
return null;
}
public List getTechParams() {
return techParams;
}
abstract String getDescription();
void write(IdWriter writer) throws IOException {
writer.writeString(techName);
writer.writeBoolean(false);
}
@Override
public String toString() {
return techName;
}
public static TechFactory getGenericFactory() {
return new FromClass("generic", "com.sun.electric.technology.technologies.Generic");
}
public static Map getKnownTechs() {
LinkedHashMap m = new LinkedHashMap();
c(m, "artwork", "com.sun.electric.technology.technologies.Artwork");
c(m, "fpga", "com.sun.electric.technology.technologies.FPGA");
c(m, "schematic", "com.sun.electric.technology.technologies.Schematics");
r(m, "bicmos", "technology/technologies/bicmos.xml");
r(m, "bipolar", "technology/technologies/bipolar.xml");
r(m, "cmos", "technology/technologies/cmos.xml");
r(m, "efido", "technology/technologies/efido.xml");
// c(m, "efido", "com.sun.electric.technology.technologies.EFIDO");
c(m, "gem", "com.sun.electric.technology.technologies.GEM");
r(m, "pcb", "technology/technologies/pcb.xml");
r(m, "rcmos", "technology/technologies/rcmos.xml");
p(m, "mocmos", "com.sun.electric.technology.technologies.MoCMOS");
r(m, "mocmosold", "technology/technologies/mocmosold.xml");
r(m, "mocmossub", "technology/technologies/mocmossub.xml");
r(m, "nmos", "technology/technologies/nmos.xml");
r(m, "tft", "technology/technologies/tft.xml");
p(m, "tsmc180", "com.sun.electric.plugins.tsmc.TSMC180");
p(m, "cmos90", "com.sun.electric.plugins.tsmc.CMOS90");
r(m, "tsmcSun40GP", "plugins/tsmc/tsmcSun40GP.xml");
// c(m, "tsmc45", "com.sun.electric.plugins.tsmc.TSMC45");
return Collections.unmodifiableMap(m);
}
public static TechFactory getTechFactory(String techName) {
return getKnownTechs().get(techName);
}
TechFactory(String techName) {
this(techName, Collections.emptyList());
}
TechFactory(String techName, List techParams) {
this.techName = techName;
this.techParams = Collections.unmodifiableList(new ArrayList(techParams));
}
private static void p(Map m, String techName, String techClassName) {
TechFactory techFactory;
List params;
try {
Class> techClass = Class.forName(techClassName);
Method getTechParamsMethod = techClass.getMethod("getTechParams");
params = (List) getTechParamsMethod.invoke(null);
techFactory = new FromParamClass(techName, techClass, params);
} catch (Exception e) {
TextUtils.recordMissingTechnology(techName);
return;
}
m.put(techName, techFactory);
}
private static void c(Map m, String techName, String techClassName) {
m.put(techName, new FromClass(techName, techClassName));
}
private static void r(Map m, String techName, String resourceName) {
assert techName != null;
URL url = Main.class.getResource(resourceName);
if (url == null) {
return;
}
m.put(techName, new FromXml(techName, false, url, null));
}
abstract Technology newInstanceImpl(Generic generic, Map paramValues) throws Exception;
public Xml.Technology getXml(final Map params) throws Exception {
return getXml(params, null);
}
public abstract Xml.Technology getXml(final Map params, Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy