Skip to content

Instantly share code, notes, and snippets.

@Nava2
Last active August 29, 2015 14:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Nava2/4f1172d647437a1cf5ca to your computer and use it in GitHub Desktop.
Umpr Repository Tutorial
/**
*
*/
package cruise.umple.umpr.core.repositories;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import cruise.umple.compiler.UmpleImportType;
import cruise.umple.umpr.core.DiagramType;
import cruise.umple.umpr.core.Repository;
import cruise.umple.umpr.core.entities.ImportEntity;
import cruise.umple.umpr.core.entities.ImportEntityFactory;
import cruise.umple.umpr.core.util.Networks;
/**
* @author kevin
*
*/
class ISO20022EcoreRepository implements Repository {
private static final String GIST_URL = "https://gist.githubusercontent.com/Nava2/4ca3335224d51c185c0b/" +
"raw/87067f5d6889d9efa6032de25331fde6d1d0f88c/iso20022.ecore";
//Creates ImportEntity instances
private final ImportEntityFactory factory;
@Inject
ISO20022EcoreRepository(ImportEntityFactory importEntityFactory) {
this.factory = importEntityFactory;
}
/* (non-Javadoc)
* @see cruise.umple.umpr.core.Repository#getName()
*/
@Override
public String getName() {
return "ISO20022";
}
/* (non-Javadoc)
* @see cruise.umple.umpr.core.Repository#getDescription()
*/
@Override
public String getDescription() {
return "ISO20022 ECore model from http://www.iso20022.org/e_dictionary.page, "
+ "stored statically at: " + GIST_URL;
}
/* (non-Javadoc)
* @see cruise.umple.umpr.core.Repository#getDiagramType()
*/
@Override
public DiagramType getDiagramType() {
return DiagramType.CLASS;
}
/* (non-Javadoc)
* @see cruise.umple.umpr.core.Repository#getImports()
*/
@Override
public Stream<ImportEntity> getImports() {
try {
final URL url = new URL(GIST_URL);
final ImportEntity entity = factory.createUrlEntity(this, Paths.get(url.getPath()),
UmpleImportType.ECORE, url);
final List<ImportEntity> out = new ArrayList<>();
out.add(entity);
return out.stream();
} catch (MalformedURLException mue) {
throw Throwables.propagate(mue);
}
}
/* (non-Javadoc)
* @see cruise.umple.umpr.core.Repository#isAccessible()
*/
@Override
public boolean isAccessible() {
return Networks.ping(GIST_URL, 200);
}
}
package cruise.umple.umpr.core.repositories;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.multibindings.Multibinder;
import cruise.umple.umpr.core.Repository;
/**
* Module that binds all Repository instances in for the main application to load at runtime.
*/
public class RepositoryModule implements Module {
@Override
public void configure(Binder binder) {
Multibinder<Repository> mbinder = Multibinder.newSetBinder(binder, Repository.class);
mbinder.addBinding().to(AtlanZooRepository.class);
mbinder.addBinding().to(ScxmlStandardRepository.class);
mbinder.addBinding().to(ISO20022EcoreRepository.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment