Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/main/java/com/yetanalytics/hlaxapi/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public HLADecoderRegistry hlaDecoderRegistry(EncoderFactory encoderFactory) {
return new HLADecoderRegistry(encoderFactory);
}

@Bean
public FomCatalog fomCatalog(FOMXML fomXml) {
return FomCatalog.fromFomXml(fomXml);
}

@Bean(destroyMethod = "close")
public ObjectCache objectCache(
XapiConfig xapiConfig,
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/com/yetanalytics/hlaxapi/cache/FomCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Optional;
import java.util.Set;
import javax.xml.xpath.XPathExpressionException;

import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -20,14 +22,24 @@
/**
* FOM-derived object metadata used by the SQLite cache.
*/
@Component
public final class FomCatalog {

private final Map<String, ObjectClassDef> classesByName;
private final Map<Integer, ObjectClassDef> classesById;
private final Map<Integer, FomAttribute> attributesById;

private FomCatalog(Map<String, ObjectClassDef> classesByName) {
this.classesByName = Collections.unmodifiableMap(classesByName);
public FomCatalog(FOMXML fomXml) {
Objects.requireNonNull(fomXml, "fomXml");
CatalogBuilder builder = new CatalogBuilder(fomXml);
Document document = fomXml.getDoc();
Element objects = firstElement(document.getDocumentElement(), "objects");
if (objects != null) {
for (Element objectClass : childElements(objects, "objectClass")) {
builder.parseObjectClass(objectClass, null, new ArrayList<>());
}
}
this.classesByName = builder.classesByName;

Map<Integer, ObjectClassDef> byId = new LinkedHashMap<>();
Map<Integer, FomAttribute> attrsById = new LinkedHashMap<>();
Expand All @@ -41,19 +53,6 @@ private FomCatalog(Map<String, ObjectClassDef> classesByName) {
this.attributesById = Collections.unmodifiableMap(attrsById);
}

public static FomCatalog fromFomXml(FOMXML fomXml) {
Objects.requireNonNull(fomXml, "fomXml");
CatalogBuilder builder = new CatalogBuilder(fomXml);
Document document = fomXml.getDoc();
Element objects = firstElement(document.getDocumentElement(), "objects");
if (objects != null) {
for (Element objectClass : childElements(objects, "objectClass")) {
builder.parseObjectClass(objectClass, null, new ArrayList<>());
}
}
return new FomCatalog(builder.classesByName);
}

public Collection<ObjectClassDef> objectClasses() {
return classesByName.values();
}
Expand Down
Loading