[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[stp-commits] r3328 - org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.introspection/src/org/eclipse/stp/sca/introspection
|
- From: genie@xxxxxxxxxxx
- Date: Tue, 15 Sep 2009 13:00:13 -0400 (EDT)
- Delivered-to: stp-commits@eclipse.org
Author: sdrapeau
Date: 2009-09-15 13:00:13 -0400 (Tue, 15 Sep 2009)
New Revision: 3328
Added:
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.introspection/src/org/eclipse/stp/sca/introspection/CompositeImplementationResolver.java
Log:
Fix for bug #289481
Added: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.introspection/src/org/eclipse/stp/sca/introspection/CompositeImplementationResolver.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.introspection/src/org/eclipse/stp/sca/introspection/CompositeImplementationResolver.java (rev 0)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.introspection/src/org/eclipse/stp/sca/introspection/CompositeImplementationResolver.java 2009-09-15 17:00:13 UTC (rev 3328)
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2007-2008-2009
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jamil Shaikh (RIM) <jshaikh@xxxxxxx> - initial API and implementation
+ */
+package org.eclipse.stp.sca.introspection;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.ecore.util.FeatureMapUtil;
+import org.eclipse.stp.sca.Component;
+import org.eclipse.stp.sca.ComponentReference;
+import org.eclipse.stp.sca.ComponentService;
+import org.eclipse.stp.sca.Composite;
+import org.eclipse.stp.sca.Interface;
+import org.eclipse.stp.sca.Property;
+import org.eclipse.stp.sca.PropertyValue;
+import org.eclipse.stp.sca.Reference;
+import org.eclipse.stp.sca.SCAImplementation;
+import org.eclipse.stp.sca.ScaFactory;
+import org.eclipse.stp.sca.ScaPackage;
+import org.eclipse.stp.sca.Service;
+import org.eclipse.stp.sca.util.ScaCompositeUtils;
+
+/**
+ * @author Jamil Shaikh - RIM
+ * @contributor Stephane Drapeau - Added setInterface, setService, setReference
+ * methods, resolve(Component), resolve(Composite) + refactoring.
+ */
+public class CompositeImplementationResolver implements Resolver {
+
+ /**
+ * Resolve promoted services from the composite
+ *
+ * @param component
+ * - current component
+ * @param Composite
+ * composite passed in
+ */
+ public void resolveServices(Component component, Composite composite) {
+ for (Service service : composite.getService()) {
+ setService(component, service);
+ }
+ //FIXME
+ /*
+ // create current services map
+ Map<String, Service> serviceMap = new HashMap<String, Service>();
+ // create missing services map
+ Map<String, Service> missingServiceMap = new HashMap<String, Service>();
+
+ //retrieve services from the composite
+ EList<Service> newServiceList = composite.getService();
+
+ // register missing services
+ for (Service service : newServiceList) {
+ // Test if interface type as already been registered
+ if (!serviceMap.containsValue(service.getName())) {
+ String sName = service.getName();
+ missingServiceMap.put(sName, service);
+ }
+ }
+
+ Set<String> serviceSet = missingServiceMap.keySet();
+ for (String key : serviceSet) {
+ ComponentService c = ScaFactory.eINSTANCE.createComponentService();
+ c.setName(key);
+ c.setInterface(missingServiceMap.get(key).getInterface());
+ c.setCallback(missingServiceMap.get(key).getCallback());
+ // add component service to the model
+ component.getService().add(c);
+ }
+ */
+ }
+
+ /**
+ * Resolve promoted references from the composite
+ *
+ * @param component
+ * - current component
+ * @param Composite
+ * composite passed in
+ */
+ public void resolveReferences(Component component, Composite composite) {
+ for (Reference reference : composite.getReference()) {
+ setReference(component, reference);
+ }
+ //FIXME
+ /*
+ // create current reference map
+ Map<String, Reference> referenceMap = new HashMap<String, Reference>();
+ // create missing reference map
+ Map<String, Reference> missingReferenceMap = new HashMap<String, Reference>();
+
+ //retrieve reference from the composite
+ EList<Reference> newReferenceList = composite.getReference();
+
+ // register missing reference
+ for (Reference reference : newReferenceList) {
+ // Test if interface type as already been registered
+ if (!referenceMap.containsValue(reference.getName())) {
+ String rName = reference.getName();
+ missingReferenceMap.put(rName, reference);
+ }
+ }
+
+ Set<String> referenceSet = missingReferenceMap.keySet();
+ for (String key : referenceSet) {
+ ComponentReference r = ScaFactory.eINSTANCE.createComponentReference();
+ r.setName(key);
+ r.setInterface(missingReferenceMap.get(key).getInterface());
+ r.setCallback(missingReferenceMap.get(key).getCallback());
+ // add component reference to the model
+ component.getReference().add(r);
+ }
+ */
+ }
+
+ /**
+ * Resolve promoted properties from composite
+ *
+ * @param component
+ * - current component
+ * @param Composite
+ * composite passed in
+ */
+ public void resolveProperties(Component component, Composite composite) {
+ // create current properties map
+ Map<String, Property> propertyMap = new HashMap<String, Property>();
+ // create missing properties map
+ Map<String, Property> missingPropertyMap = new HashMap<String, Property>();
+
+ // retrieve properties from the composite
+ EList<Property> newPropertyList = composite.getProperty();
+
+ // register missing properties
+ for (Property property : newPropertyList) {
+ // Test if interface type as already been registered
+ if (!propertyMap.containsValue(property.getName())) {
+ String pName = property.getName();
+ missingPropertyMap.put(pName, property);
+ }
+ }
+
+ Set<String> propertySet = missingPropertyMap.keySet();
+ for (String key : propertySet) {
+ PropertyValue p = ScaFactory.eINSTANCE.createPropertyValue();
+ p.setName(key);
+ p.setType(missingPropertyMap.get(key).getType());
+ p.setValue(missingPropertyMap.get(key).getValue());
+ // add component property to the model
+ component.getProperty().add(p);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.stp.sca.introspection.Resolver#resolve(org.eclipse.stp.sca
+ * .Composite)
+ */
+ public Composite resolve(Composite composite) {
+ for (Component component : composite.getComponent()) {
+ this.resolve(component);
+ }
+ return composite;
+ }
+
+ private void resolve(Component component) {
+ if (!(component.getImplementation() instanceof SCAImplementation)) {
+ return;
+ }
+ SCAImplementation scaImplem = (SCAImplementation) component
+ .getImplementation();
+ QName compositeName = scaImplem.getName();
+ if (compositeName != null) {
+ // FIXME
+ IFile compositeFile = null;
+ // ResourceUtils.getCompositeFile(compositeName
+ // .getLocalPart()
+ // + ".composite");
+ if (compositeFile != null) {
+ Composite includedComposite = ScaCompositeUtils
+ .getComposite(compositeFile);
+ this.resolveServices(component, includedComposite);
+ this.resolveReferences(component, includedComposite);
+ this.resolveProperties(component, includedComposite);
+ }
+ }
+ }
+
+ private void setService(Component component, Service service) {
+ ComponentService componentService = ScaFactory.eINSTANCE
+ .createComponentService();
+ componentService.setName(service.getName());
+ if (service.getInterface() != null) {
+ this.setInterface(componentService.getInterfaceGroup(),
+ ScaPackage.Literals.BASE_SERVICE__INTERFACE_GROUP, service
+ .getInterfaceGroup().getEStructuralFeature(0),
+ service.getInterface());
+ } else if (service.getPromote2() != null
+ && service.getPromote2().getInterface() != null) {
+ this.setInterface(componentService.getInterfaceGroup(),
+ ScaPackage.Literals.BASE_SERVICE__INTERFACE_GROUP, service
+ .getPromote2().getInterfaceGroup()
+ .getEStructuralFeature(0), service.getPromote2()
+ .getInterface());
+ }
+ component.getService().add(componentService);
+ }
+
+ private void setInterface(FeatureMap interfaceGroup,
+ EAttribute interfaceGroupLiteral,
+ EStructuralFeature eStructuralFeature, Interface interfac) {
+ ((FeatureMap.Internal) interfaceGroup).clear();
+ ((FeatureMap.Internal) interfaceGroup).add(interfaceGroupLiteral,
+ FeatureMapUtil.createEntry(eStructuralFeature, interfac));
+ }
+
+ private void setReference(Component component, Reference reference) {
+ ComponentReference componentReference = ScaFactory.eINSTANCE
+ .createComponentReference();
+ componentReference.setName(reference.getName());
+ if (reference.getInterface() != null) {
+ this.setInterface(componentReference.getInterfaceGroup(),
+ ScaPackage.Literals.BASE_REFERENCE__INTERFACE_GROUP,
+ reference.getInterfaceGroup().getEStructuralFeature(0),
+ reference.getInterface());
+ } else if (reference.getPromote2() != null
+ && reference.getPromote2().getInterface() != null) {
+ this.setInterface(componentReference.getInterfaceGroup(),
+ ScaPackage.Literals.BASE_REFERENCE__INTERFACE_GROUP,
+ reference.getPromote2().getInterfaceGroup()
+ .getEStructuralFeature(0), reference.getPromote2()
+ .getInterface());
+ }
+ component.getReference().add(componentReference);
+ }
+
+}
Property changes on: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.introspection/src/org/eclipse/stp/sca/introspection/CompositeImplementationResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain