private <T extends Connection> T createConnection ( final EClass connectionClass, final Class<T> clazz, final Global global, final Local local ) { final T connection = clazz.cast ( OsgiFactory.eINSTANCE.create ( connectionClass ) ); final String tag = connection.getTypeTag (); final String cname = String.format ( "global.%s.to.%s.%s", Names.makeName ( global.getGlobal () ), local.getId (), tag ); connection.setName ( cname ); // set credentials connection.setCredentials ( EcoreUtil.copy ( findCredentials ( global, local ) ) ); // add connection to "from" global.getGlobal ().getConnections ().add ( connection ); // point connection to "to" final LinkedList<Endpoint> endpoints = new LinkedList<> (); for ( final Exporter exporter : local.getLocal ().getExporter () ) { endpoints.addAll ( connection.getPossibleEndpoints ( exporter ) ); } if ( endpoints.isEmpty () ) { throw new IllegalStateException ( String.format ( "Unable to find an exporter that could serve as endpoint for connection type %s on master %s", connectionClass.getName (), local.getLocal ().getName () ) ); } final Endpoint endpoint = endpoints.getFirst (); connection.setEndpoint ( endpoint ); // FIXME: adding connection analyzers to "app", in phase 1 return connection; }