Skip to content

Commit

Permalink
Stubs for class registry
Browse files Browse the repository at this point in the history
  • Loading branch information
fvilla committed Dec 2, 2024
1 parent c777b28 commit 6ba5509
Show file tree
Hide file tree
Showing 12 changed files with 663 additions and 637 deletions.
144 changes: 84 additions & 60 deletions klab.core.api/src/main/java/org/integratedmodelling/klab/api/Klab.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.integratedmodelling.klab.api;

import org.integratedmodelling.klab.api.collections.Pair;
import org.integratedmodelling.klab.api.geometry.Geometry;
import org.integratedmodelling.klab.api.knowledge.*;
import org.integratedmodelling.klab.api.knowledge.observation.scale.Extent;
Expand All @@ -13,21 +14,21 @@
import org.integratedmodelling.klab.api.services.runtime.extension.KlabFunction;
import org.integratedmodelling.klab.api.services.runtime.extension.Library;

import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
* Holds global configurations and functions that allow generic interfaces to expose constructor methods that
* produce implementation classes that depend on complex dependencies. Implements a poor-man injection pattern
* that needs to be configured in a static block, as done in <code>klab.services.core</code>. This permits
* complex classes like Scale or Projection to have generic builders declared in the API package.
* Global constants, enums and a registry for implementation of the basic interfaces.
*
* @author Ferd
*/
public enum Klab {

INSTANCE;


/**
* Error codes for all situations. These can (should) be passed, along with an ErrorContext, to
* {@link org.integratedmodelling.klab.api.services.runtime.Channel#error(Object...)} to qualify the
Expand Down Expand Up @@ -83,73 +84,96 @@ public interface Extents {
public static final String TIME = "time";

}

}

/**
* This is implemented and configured by services so that static constructors of classes that need complex
* dependencies can be provided with the correspondent interfaces in the <code>klab.core.api</code>
* package. Implements a poor-man injection pattern without the pain of actual injection.
* Register a class as an implementation of a given interface. Constructor parameters will be recorded to
* speed up lookup when newInstance() is called. Registering an interface more than once will log a
* warning.
*
* @author Ferd
* @param implementationClass
* @param interfaceClass
*/
public interface Configuration {

Observable promoteConceptToObservable(Concept concept);

Observable.Builder getObservableBuilder(Concept observable, Scope scope);

Observable.Builder getObservableBuilder(Observable observable, Scope scope);

Scale promoteGeometryToScale(Geometry geometry, Scope scope);

Projection getDefaultSpatialProjection();

Projection getLatLonSpatialProjection();

Scale createScaleFromExtents(Collection<Extent<?>> extents);

Shape createShapeFromTextSpecification(String shapeText, Projection projection);

Projection getSpatialProjection(String string);
public void register(Class<?> implementationClass, Class<?> interfaceClass) {

Coverage promoteScaleToCoverage(Scale geometry, double coverage);

Model.Builder getModelBuilder(Observable observable);

Model.Builder getModelBuilder(Artifact.Type nonSemanticType);

Model.Builder getModelBuilder(Resource resource);

Model.Builder getModelBuilder(Object value);

Model.Builder getModelLearner(String outputResourceUrn);

Quantity parseQuantity(String quantityDescription);

/**
* Deep copy of an extent - anything not immutable must be a new object.
*
* @param extent
* @return
*/
Extent<?> createExtentCopy(Extent<?> extent);
}

private Configuration configuration;

/**
* Call this in the static block of the core package configuration to ensure that the constructors know
* how to do their job.
*
* @param configuration
* @param interfaceClass
* @param arguments
* @param <T>
* @return
*/
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}
public <T> T newInstance(Class<T> interfaceClass, Object... arguments) {

public Configuration getConfiguration() {
return this.configuration;
}


// /**
// * This is implemented and configured by services so that static constructors of classes that need complex
// * dependencies can be provided with the correspondent interfaces in the <code>klab.core.api</code>
// * package. Implements a poor-man injection pattern without the pain of actual injection.
// *
// * @author Ferd
// * @deprecated use the registry functions
// */
// public interface Configuration {
//
// Observable promoteConceptToObservable(Concept concept);
//
// Observable.Builder getObservableBuilder(Concept observable, Scope scope);
//
// Observable.Builder getObservableBuilder(Observable observable, Scope scope);
//
// Scale promoteGeometryToScale(Geometry geometry, Scope scope);
//
// Projection getDefaultSpatialProjection();
//
// Projection getLatLonSpatialProjection();
//
// Scale createScaleFromExtents(Collection<Extent<?>> extents);
//
// Shape createShapeFromTextSpecification(String shapeText, Projection projection);
//
// Projection getSpatialProjection(String string);
//
// Coverage promoteScaleToCoverage(Scale geometry, double coverage);
//
// Model.Builder getModelBuilder(Observable observable);
//
// Model.Builder getModelBuilder(Artifact.Type nonSemanticType);
//
// Model.Builder getModelBuilder(Resource resource);
//
// Model.Builder getModelBuilder(Object value);
//
// Model.Builder getModelLearner(String outputResourceUrn);
//
// Quantity parseQuantity(String quantityDescription);
//
// /**
// * Deep copy of an extent - anything not immutable must be a new object.
// *
// * @param extent
// * @return
// */
// Extent<?> createExtentCopy(Extent<?> extent);
// }
//
// private Configuration configuration;
//
// /**
// * Call this in the static block of the core package configuration to ensure that the constructors know
// * how to do their job.
// *
// * @param configuration
// */
// public void setConfiguration(Configuration configuration) {
// this.configuration = configuration;
// }
//
// public Configuration getConfiguration() {
// return this.configuration;
// }

}
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
package org.integratedmodelling.klab.api.engine.distribution.impl;

import org.integratedmodelling.klab.api.engine.distribution.Build;
import org.integratedmodelling.klab.api.engine.distribution.Distribution;
import org.integratedmodelling.klab.api.engine.distribution.Product;
import org.integratedmodelling.klab.api.engine.distribution.RunningInstance;
import org.integratedmodelling.klab.api.scope.Scope;
import org.integratedmodelling.klab.api.utils.PropertyBean;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;

/**
* {@link Distribution} bean which implements all the properties and can be initialized from and saved to a
* {@link java.util.Properties} object. Subclasses will need to define any further properties.
*/
public abstract class AbstractDistributionImpl extends PropertyBean implements Distribution {

private Collection<Product> products = new ArrayList<>();

@Override
public Collection<Product> getProducts() {
return products;
}


public AbstractDistributionImpl() {
super(null);
}

public AbstractDistributionImpl(File file) {
super(file);
}

@Override
public Product findProduct(Product.ProductType productType) {
for (var product : products) {
if (product.getProductType() == productType) {
return product;
}
}
return null;
}

/**
* This is used by {@link LocalBuildImpl} so that we can run the build in more capable implementations by
* just overriding this.
*
* @param build
* @param scope
* @return
*/
public RunningInstance runBuild(Build build, Scope scope) {
return null;
}

public RunningInstance getInstance(Build build, Scope scope) {
return null;
}



}
//package org.integratedmodelling.klab.api.engine.distribution.impl;
//
//import org.integratedmodelling.klab.api.engine.distribution.Build;
//import org.integratedmodelling.klab.api.engine.distribution.Distribution;
//import org.integratedmodelling.klab.api.engine.distribution.Product;
//import org.integratedmodelling.klab.api.engine.distribution.RunningInstance;
//import org.integratedmodelling.klab.api.scope.Scope;
//import org.integratedmodelling.klab.api.utils.PropertyBean;
//
//import java.io.File;
//import java.util.ArrayList;
//import java.util.Collection;
//
///**
// * {@link Distribution} bean which implements all the properties and can be initialized from and saved to a
// * {@link java.util.Properties} object. Subclasses will need to define any further properties.
// */
//public abstract class AbstractDistributionImpl extends PropertyBean implements Distribution {
//
// private Collection<Product> products = new ArrayList<>();
//
// @Override
// public Collection<Product> getProducts() {
// return products;
// }
//
//
// public AbstractDistributionImpl() {
// super(null);
// }
//
// public AbstractDistributionImpl(File file) {
// super(file);
// }
//
// @Override
// public Product findProduct(Product.ProductType productType) {
// for (var product : products) {
// if (product.getProductType() == productType) {
// return product;
// }
// }
// return null;
// }
//
// /**
// * This is used by {@link LocalBuildImpl} so that we can run the build in more capable implementations by
// * just overriding this.
// *
// * @param build
// * @param scope
// * @return
// */
// public RunningInstance runBuild(Build build, Scope scope) {
// return null;
// }
//
// public RunningInstance getInstance(Build build, Scope scope) {
// return null;
// }
//
//
//
//}
Loading

0 comments on commit 6ba5509

Please sign in to comment.