use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.
the class TransferFromIli method isTransferableView.
public static boolean isTransferableView(Object modelo) {
if (!(modelo instanceof View)) {
return false;
}
View view = (View) modelo;
Topic parent = (Topic) view.getContainer();
if (!parent.isViewTopic()) {
return false;
}
if (view.isTransient()) {
return false;
}
return true;
}
use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.
the class TransferFromIli method setupTopicTagMap.
/**
* setup a mapping from a qualified model or topic name
* to the corresponding java object.
*/
private HashMap setupTopicTagMap(TransferDescription td) {
HashMap ret = new HashMap();
Iterator modeli = td.iterator();
while (modeli.hasNext()) {
Object mObj = modeli.next();
if (mObj instanceof Model) {
Model model = (Model) mObj;
ret.put(model.getScopedName(null), model);
Iterator topici = model.iterator();
while (topici.hasNext()) {
Object tObj = topici.next();
if (tObj instanceof Topic) {
Topic topic = (Topic) tObj;
ret.put(topic.getScopedName(null), topic);
}
}
}
}
return ret;
}
use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.
the class TransferFromIli method generatModelEles.
private void generatModelEles(java.util.List<Element> modelEles, int pass) throws Ili2dbException {
Iterator modeli = modelEles.iterator();
while (modeli.hasNext()) {
Object modelo = modeli.next();
if (modelo instanceof Model) {
Model model = (Model) modelo;
// generateModel(model);
} else if (modelo instanceof Topic) {
// generateTopic((Topic)modelo);
} else if (modelo instanceof Domain) {
if (pass == 2) {
generateDomain((Domain) modelo);
visitedElements.add((Domain) modelo);
}
} else if (modelo instanceof Viewable) {
if (modelo instanceof Table && ((Table) modelo).isIli1LineAttrStruct()) {
// skip it
} else if ((modelo instanceof View) && !isTransferableView(modelo)) {
// skip it
} else {
try {
ViewableWrapper wrapper = class2wrapper.get((Viewable) modelo);
if (wrapper != null) {
generateViewable(wrapper, pass);
}
if (pass == 2) {
visitedElements.add((Viewable) modelo);
}
} catch (Ili2dbException ex) {
throw new Ili2dbException("mapping of " + ((Viewable) modelo).getScopedName(null) + " failed", ex);
}
}
} else if (modelo instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) modelo;
if (attr.getDomainResolvingAll() instanceof SurfaceOrAreaType) {
for (int epsgCode : getEpsgCodes(attr, srsModelAssignment, defaultCrsCode)) {
generateItfLineTable(attr, epsgCode, pass);
}
} else if (attr.getDomainResolvingAll() instanceof EnumerationType) {
if (pass == 2) {
visitedEnums.add(attr);
}
} else {
// skip it
}
} else {
// skip it
}
}
}
use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.
the class MetaAttrUtility method visitElement.
// Recursively iterate data model and write all found meta-attributes
private static void visitElement(HashMap<String, HashMap<String, String>> entries, Element el, NameMapping class2wrapper) throws Ili2dbException {
Settings metaValues = el.getMetaValues();
try {
if (metaValues.getValues().size() > 0) {
for (String attr : metaValues.getValues()) {
HashMap<String, String> exstValues = getMetaValues(entries, el);
exstValues.put(attr, metaValues.getValue(attr));
}
}
if (el instanceof RoleDef) {
RoleDef role = (RoleDef) el;
HashMap<String, String> exstValues = getMetaValues(entries, el);
exstValues.put(ILI2DB_ILI_ASSOC_KIND, mapRoleKind(role.getKind()));
exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MIN, mapCardinality(role.getCardinality().getMinimum()));
exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MAX, mapCardinality(role.getCardinality().getMaximum()));
}
if (el instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) el;
HashMap<String, String> exstValues = getMetaValues(entries, el);
exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MIN, mapCardinality(getDomain(attr).getCardinality().getMinimum()));
exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MAX, mapCardinality(getDomain(attr).getCardinality().getMaximum()));
}
if (el instanceof Topic) {
Topic topic = (Topic) el;
HashMap<String, String> exstValues = getMetaValues(entries, el);
List<Viewable<?>> viewables = topic.getTransferViewables();
List<String> tableNames = new ArrayList<String>();
for (Viewable aclass : viewables) {
String tableName = class2wrapper.mapIliClassDef(aclass);
if (!tableNames.contains(tableName)) {
tableNames.add(tableName);
}
}
Collections.sort(tableNames);
StringBuffer classesInTopic = new StringBuffer();
String sep = "";
for (String tableName : tableNames) {
classesInTopic.append(sep);
classesInTopic.append(tableName);
sep = " ";
}
exstValues.put(ILI2DB_ILI_TOPIC_CLASSES, classesInTopic.toString());
Domain bidDomain = topic.getBasketOid();
if (bidDomain != null) {
exstValues.put(ILI2DB_ILI_TOPIC_BIDDOMAIN, bidDomain.getScopedName());
}
}
} catch (RuntimeException e) {
EhiLogger.traceUnusualState(el.getScopedName() + ": " + e.getMessage());
throw e;
}
if (el instanceof Container) {
Container e = (Container) el;
Iterator it = e.iterator();
while (it.hasNext()) {
visitElement(entries, (Element) it.next(), class2wrapper);
}
}
}
use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.
the class TransferToXtf method getTopicByBasketId.
private Topic getTopicByBasketId(long basketSqlId, StringBuilder basketXtfId, Map<String, String> genericDomains) throws IoxException {
String sqlName = DbNames.BASKETS_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
String topicName = null;
String bid = null;
String domains = null;
java.sql.PreparedStatement getstmt = null;
java.sql.ResultSet res = null;
try {
String stmt = "SELECT " + DbNames.BASKETS_TAB_TOPIC_COL + "," + DbNames.T_ILI_TID_COL + "," + DbNames.BASKETS_TAB_DOMAINS_COL + " FROM " + sqlName + " WHERE " + colT_ID + "= ?";
if (config.isVer3_export()) {
stmt = "SELECT " + DbNames.BASKETS_TAB_TOPIC_COL + "," + DbNames.T_ILI_TID_COL + " FROM " + sqlName + " WHERE " + colT_ID + "= ?";
}
EhiLogger.traceBackendCmd(stmt);
getstmt = conn.prepareStatement(stmt);
getstmt.setLong(1, basketSqlId);
res = getstmt.executeQuery();
if (res.next()) {
topicName = res.getString(1);
bid = res.getString(2);
if (!config.isVer3_export()) {
domains = res.getString(3);
}
}
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to query " + sqlName, ex);
} finally {
if (res != null) {
try {
res.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError(ex);
}
res = null;
}
if (getstmt != null) {
try {
getstmt.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError(ex);
}
getstmt = null;
}
}
if (topicName != null) {
Topic topic = getTopicDef(td, topicName);
if (topic == null) {
throw new IoxException("unknown Topic " + topicName + " in table " + sqlName);
}
if (config.getCrsExportModels() != null) {
// crs translate topic
Topic crsTranslatedTopic1 = (Topic) crsFilter.get(topic);
Topic crsTranslatedTopic2 = (Topic) crsFilterToTarget.get(topic);
// if translated topic is in export model, use translated one
if (crsTranslatedTopic1 != null && crsTranslatedTopic1.getContainer().getName().equals(config.getCrsExportModels())) {
topic = crsTranslatedTopic1;
} else if (crsTranslatedTopic2 != null && crsTranslatedTopic2.getContainer().getName().equals(config.getCrsExportModels())) {
topic = crsTranslatedTopic2;
}
}
if (bid != null) {
basketXtfId.append(bid);
}
if (domains != null) {
genericDomains.putAll(Xtf24Reader.parseDomains(domains));
}
return topic;
}
return null;
}
Aggregations