private boolean influencesFragment(ReuseExtensionActivator rexActivator, Fragment fragment) { ReuseExtension rex = rexActivator.getReuseExtension(); if (rex instanceof ComponentModelSpecification) { for (EObject root : fragment.getContents()) { for (RootElementContext rootElementContext : rex.getRootElementContexts()) { if (rootElementContext.getEBoundClass().isInstance(root)) { Map<String, String> args = new LinkedHashMap<String, String>(); for (Argument arg : rexActivator.getArguments()) { args.put(arg.getParameter(), arg.getValue()); } if (EvaluatorUtil.eval( fragment.getUFI(), root, rootElementContext.getIsExpression(), args)) { return true; } } } } } return false; }
private void computeAndCacheCompositionInterface( List<String> ufi, Resource fragmentResource, List<ReuseExtensionActivator> rexActivatorList, ResourceSet resourceSet, IndexMetaData metaData) { Fragment fragment = null; // physical or composed? List<Constraint> constraints = FacetUtil.buildConstraints( IndexConstants.COLUMN_COMPOSED_FRAGMENT, ResourceUtil.idString(ufi)); FacetedRequest request = FacetUtil.buildFacetedRequest(constraints); List<IndexRow> response = IndexUtil.INSTANCE.getIndex(request); if (response.isEmpty()) { fragment = FragmentFactory.eINSTANCE.createPhysicalFragment(); } else { fragment = FragmentFactory.eINSTANCE.createComposedFragment(); } // load fragment.getUFI().addAll(ufi); fragment.getContents().addAll(fragmentResource.getContents()); // find reuse extension activators for (ReuseExtensionActivator rexActivator : rexActivatorList) { if (rexActivator.getReuseExtension() instanceof ComponentModelSpecification) { if (influencesFragment(rexActivator, fragment)) { fragment.getComponentModelActivators().add(rexActivator); } } } // compute composition interface (post processors might need diagrams) if (!fragment.getContents().isEmpty()) { for (URI fragmentDiagramURI : ReuseResources.INSTANCE.getDiagramURIs(ufi)) { Resource fragmentDiagramResource = null; try { fragmentDiagramResource = resourceSet.getResource(fragmentDiagramURI, true); } catch (Exception e) { // ok } if (fragmentDiagramResource != null) { fragment.getDiagrams().addAll(fragmentDiagramResource.getContents()); } } } CompositionInterfaceComputerUtil.compute(fragment); // index (cache) Resource tempXMIResource = resourceSet.createResource(URI.createURI("temp:/temp.xmi")); tempXMIResource.getContents().add(fragment); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { tempXMIResource.save(outputStream, resourceSet.getLoadOptions()); metaData.putSingle(IndexConstants.COLUMN_FRAGMENT, outputStream.toString("UTF-8")); } catch (IOException e) { e.printStackTrace(); } resourceSet.getResources().remove(tempXMIResource); // are there external computers registered? // TODO #1656: test this DerivedCompositionProgram derivedCp = CompositionProgramExtractorUtil.extract(fragment); if (derivedCp != null && derivedCp.getUCPI() != null && !derivedCp.getUCPI().isEmpty()) { URI derivedCpURI = SokanReuseResourceUtil.getDerivedCompositionProgramURI( derivedCp.getUCPI(), fragment.getUFI(), null); Resource resource = createResourceForDerivedCompositionProgram(derivedCp, derivedCpURI, resourceSet); ReuseResourcesUtil.completeCompositionProgram(resource); } }