[savara-commits] savara SVN: r76 - in tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel: src/java/org/jboss/savara/tools/bpel/model/change and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sun Nov 8 10:03:12 EST 2009
Author: objectiser
Date: 2009-11-08 10:03:11 -0500 (Sun, 08 Nov 2009)
New Revision: 76
Added:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ModelChangeUtils.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/model/change/
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/model/change/ModelChangeUtilsTest.java
Removed:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationModelChangeRule.java
Modified:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/META-INF/MANIFEST.MF
Log:
Store contract to role association in context to deal with composed conversations.
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/META-INF/MANIFEST.MF
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/META-INF/MANIFEST.MF 2009-11-07 00:25:46 UTC (rev 75)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/META-INF/MANIFEST.MF 2009-11-08 15:03:11 UTC (rev 76)
@@ -26,7 +26,7 @@
org.jboss.savara.tools.bpel.parser.BPELModelParserRule,
org.jboss.savara.tools.bpel.model.BPELNotation,
org.jboss.savara.tools.bpel.model.change.LanguageToConversationModelChangeRule,
- org.jboss.savara.tools.bpel.model.change.ConversationModelChangeRule,
+ org.jboss.savara.tools.bpel.model.change.ConversationChangeRule,
org.jboss.savara.tools.bpel.model.change.WhileModelChangeRule,
org.jboss.savara.tools.bpel.model.change.WhenModelChangeRule,
org.jboss.savara.tools.bpel.model.change.IfModelChangeRule,
Copied: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java (from rev 71, tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationModelChangeRule.java)
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java 2009-11-08 15:03:11 UTC (rev 76)
@@ -0,0 +1,243 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.bpel.model.change;
+
+import org.jboss.savara.tools.bpel.generator.Generator;
+import org.jboss.savara.tools.bpel.model.*;
+import org.jboss.savara.tools.bpel.model.component.*;
+import org.jboss.savara.tools.bpel.model.component.Import;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.contract.model.Contract;
+import org.scribble.conversation.model.*;
+import org.scribble.extensions.RegistryInfo;
+
+/**
+ * This is the model change rule for the Conversation.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=BPELNotation.NOTATION_CODE)
+public class ConversationChangeRule extends AbstractModelChangeRule {
+
+ //private static final String NAME_SUFFIX = "_main";
+
+ /**
+ * This method determines whether the rule is appropriate
+ * for the supplied type of model, parent (in the context) and
+ * model object.
+ *
+ * @param context The context
+ * @param model The model
+ * @param mobj The model object causing the change
+ * @param ref The optional reference model object
+ * @return Whether the rule supports the supplied information
+ */
+ @Override
+ public boolean isInsertSupported(ModelChangeContext context,
+ Model model, ModelObject mobj, ModelObject ref) {
+ boolean ret=false;
+
+ if (mobj instanceof Conversation &&
+ model instanceof DefaultBPELLanguageModel) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method adds a new model object, within a
+ * parent model object, with the details supplied in
+ * another model object. The supplied model object
+ * will usually be from a different model representation
+ * (e.g. due to a merge), so the details will be
+ * copied and placed in the representation associated
+ * with the supplied model and parent model object.<p>
+ * <p>
+ * If a reference model object is supplied, then the
+ * insertion will occur relative to it. If the reference
+ * object is a block, then it means that the insertion
+ * should occur at the end of the block. Otherwise the
+ * new model object should be inserted before the
+ * reference object, within the containing block.<p>
+ * <p>
+ * If the reference object is not supplied, then the
+ * new model object should be inserted at the end of
+ * the behaviour associated with the parent in the model
+ * change context.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param mobj The model object details to be inserted
+ * @param ref The optional reference model object
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean insert(ModelChangeContext context,
+ Model model, ModelObject mobj, ModelObject ref) {
+ DefaultBPELLanguageModel bpelModel=(DefaultBPELLanguageModel)model;
+ Conversation conv=(Conversation)mobj;
+ String roleNamespace=null;
+
+ Sequence seq=new Sequence(bpelModel);
+
+ // Check if root conversation
+ if (conv.getParent() instanceof Model) {
+
+ ModelChangeUtils.initializeContracts(context, conv);
+
+ // Set the name of the process
+ bpelModel.getBPELProcess().setName(conv.getLocatedName().getName()+"_"+
+ conv.getLocatedName().getRole().getName());
+
+ // Get contract
+ //Contract contract=ModelChangeUtils.getContract(context, conv.getLocatedName().getRole().getName());
+
+ if (conv.getLocatedName().getRole().getAnnotations().containsKey(Contract.class.getName())) {
+ Contract contract=(Contract)conv.getLocatedName().
+ getRole().getAnnotations().get(Contract.class.getName());
+
+ roleNamespace = contract.getNamespace();
+
+ // Set namespace
+ bpelModel.getBPELProcess().setTargetNamespace(contract.getNamespace());
+
+ // Add other namespaces
+ for (org.scribble.contract.model.Namespace ns : contract.getNamespaces()) {
+ bpelModel.getBPELProcess().initNamespace(ns.getURI(), ns.getPrefix());
+ }
+ }
+
+ String namespace=((Model)conv.getModel()).
+ getNamespace().getName();
+
+ String ctype=null;
+
+ // Check if conversation has a 'conforms to' reference
+ if (conv.getConformsTo().size() > 0) {
+ // Set conversation type based on first 'conforms to'
+ // reference
+ ConformanceReference cref=conv.getConformsTo().get(0);
+
+ ctype = cref.getNamespace()+"."+
+ cref.getLocalpart()+"@"+
+ cref.getLocatedRole();
+ } else {
+ // Set conversation type based on conversation
+ // namespace and name
+ ctype = namespace+"."+
+ conv.getLocatedName().getName()+"@"+
+ conv.getLocatedName().getRole().getName();
+ }
+
+ if (ctype != null) {
+ bpelModel.getBPELProcess().setConversationType(ctype);
+ }
+
+ // Add import for this role
+ addImport(context, bpelModel, conv, context.getRole());
+
+ // Add import statements for partner roles
+ java.util.List<Role> roles=conv.getRoles();
+
+ for (int i=0; i < roles.size(); i++) {
+ addImport(context, bpelModel, conv, roles.get(i));
+ }
+
+ // Add import for partner link types
+ Import imp=new Import(bpelModel);
+ imp.setLocation(context.getRole().getName()+"PartnerLinkTypes.wsdl");
+ imp.setNamespace(roleNamespace);
+ imp.setImportType("http://schemas.xmlsoap.org/wsdl/");
+
+ bpelModel.getBPELProcess().addImport(imp, -1);
+
+ // Add sequence to model
+ bpelModel.getBPELProcess().setActivity(seq);
+
+ } else if (context.getParent() instanceof Sequence) {
+
+ // Create a scope
+ Scope scope=new Scope(bpelModel);
+
+ ((Sequence)context.getParent()).addActivity(scope, -1);
+
+ // NOTE: Currently needs to be added after adding scope
+ // to parent sequence, as otherwise the DOM element
+ // associated with the 'seq' sequence becomes
+ // disconnected from the actual document - due to
+ // the fact that added elements are copied (in
+ // turn due to an xml parser exception).
+ scope.setActivity(seq);
+ }
+
+ // Process the activities within the conversation
+ java.util.List<Activity> acts=conv.getBlock().getContents();
+
+ Object parent=context.getParent();
+
+ context.setParent(seq);
+
+ for (int i=0; i < acts.size(); i++) {
+ if ((acts.get(i) instanceof Definition) == false) {
+ context.insert(model, acts.get(i), null);
+ }
+ }
+
+ // Reset old parent
+ context.setParent(parent);
+
+ return(true);
+ }
+
+ /**
+ * This method adds an import statement for the contract associated with the
+ * supplied role.
+ *
+ * @param context The context
+ * @param bpelModel The model
+ * @param conv The conversation
+ * @param role The role
+ */
+ protected void addImport(ModelChangeContext context, DefaultBPELLanguageModel bpelModel,
+ Conversation conv, Role role) {
+ if (role.getAnnotations().containsKey(Contract.class.getName())) {
+ Contract contract=(Contract)role.getAnnotations().get(Contract.class.getName());
+
+ boolean gen=false;
+
+ for (int i=0; gen == false && i < contract.getInterfaces().size(); i++) {
+ if (contract.getInterfaces().get(i).getMessageExchangePatterns().size() > 0) {
+ gen = true;
+ }
+ }
+
+ if (gen) {
+ String fileName=Generator.getWSDLFileName(role,
+ conv.getLocatedName().getName(), 0);
+
+ Import imp=new Import(bpelModel);
+
+ imp.setLocation(fileName);
+ imp.setNamespace(contract.getNamespace());
+ imp.setImportType("http://schemas.xmlsoap.org/wsdl/");
+
+ bpelModel.getBPELProcess().addImport(imp, -1);
+ }
+ }
+ }
+}
Deleted: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationModelChangeRule.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationModelChangeRule.java 2009-11-07 00:25:46 UTC (rev 75)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationModelChangeRule.java 2009-11-08 15:03:11 UTC (rev 76)
@@ -1,239 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-package org.jboss.savara.tools.bpel.model.change;
-
-import org.jboss.savara.tools.bpel.generator.Generator;
-import org.jboss.savara.tools.bpel.model.*;
-import org.jboss.savara.tools.bpel.model.component.*;
-import org.jboss.savara.tools.bpel.model.component.Import;
-import org.scribble.model.*;
-import org.scribble.model.change.*;
-import org.scribble.contract.model.Contract;
-import org.scribble.conversation.model.*;
-import org.scribble.extensions.RegistryInfo;
-
-/**
- * This is the model change rule for the Conversation.
- */
- at RegistryInfo(extension=ModelChangeRule.class,notation=BPELNotation.NOTATION_CODE)
-public class ConversationModelChangeRule extends AbstractModelChangeRule {
-
- //private static final String NAME_SUFFIX = "_main";
-
- /**
- * This method determines whether the rule is appropriate
- * for the supplied type of model, parent (in the context) and
- * model object.
- *
- * @param context The context
- * @param model The model
- * @param mobj The model object causing the change
- * @param ref The optional reference model object
- * @return Whether the rule supports the supplied information
- */
- @Override
- public boolean isInsertSupported(ModelChangeContext context,
- Model model, ModelObject mobj, ModelObject ref) {
- boolean ret=false;
-
- if (mobj instanceof Conversation &&
- model instanceof DefaultBPELLanguageModel) {
- ret = true;
- }
-
- return(ret);
- }
-
- /**
- * This method adds a new model object, within a
- * parent model object, with the details supplied in
- * another model object. The supplied model object
- * will usually be from a different model representation
- * (e.g. due to a merge), so the details will be
- * copied and placed in the representation associated
- * with the supplied model and parent model object.<p>
- * <p>
- * If a reference model object is supplied, then the
- * insertion will occur relative to it. If the reference
- * object is a block, then it means that the insertion
- * should occur at the end of the block. Otherwise the
- * new model object should be inserted before the
- * reference object, within the containing block.<p>
- * <p>
- * If the reference object is not supplied, then the
- * new model object should be inserted at the end of
- * the behaviour associated with the parent in the model
- * change context.
- *
- * @param context The context
- * @param model The model being changed
- * @param mobj The model object details to be inserted
- * @param ref The optional reference model object
- * @return Whether the change has been applied
- */
- @Override
- public boolean insert(ModelChangeContext context,
- Model model, ModelObject mobj, ModelObject ref) {
- DefaultBPELLanguageModel bpelModel=(DefaultBPELLanguageModel)model;
- Conversation conv=(Conversation)mobj;
- String roleNamespace=null;
-
- Sequence seq=new Sequence(bpelModel);
-
- // Check if root conversation
- if (conv.getParent() instanceof Model) {
-
- // Set the name of the process
- bpelModel.getBPELProcess().setName(conv.getLocatedName().getName()+"_"+
- conv.getLocatedName().getRole().getName());
-
- // Get contract
- if (conv.getLocatedName().getRole().getAnnotations().containsKey(Contract.class.getName())) {
- Contract contract=(Contract)conv.getLocatedName().
- getRole().getAnnotations().get(Contract.class.getName());
-
- roleNamespace = contract.getNamespace();
-
- // Set namespace
- bpelModel.getBPELProcess().setTargetNamespace(contract.getNamespace());
-
- // Add other namespaces
- for (org.scribble.contract.model.Namespace ns : contract.getNamespaces()) {
- bpelModel.getBPELProcess().initNamespace(ns.getURI(), ns.getPrefix());
- }
- }
-
- String namespace=((Model)conv.getModel()).
- getNamespace().getName();
-
- String ctype=null;
-
- // Check if conversation has a 'conforms to' reference
- if (conv.getConformsTo().size() > 0) {
- // Set conversation type based on first 'conforms to'
- // reference
- ConformanceReference cref=conv.getConformsTo().get(0);
-
- ctype = cref.getNamespace()+"."+
- cref.getLocalpart()+"@"+
- cref.getLocatedRole();
- } else {
- // Set conversation type based on conversation
- // namespace and name
- ctype = namespace+"."+
- conv.getLocatedName().getName()+"@"+
- conv.getLocatedName().getRole().getName();
- }
-
- if (ctype != null) {
- bpelModel.getBPELProcess().setConversationType(ctype);
- }
-
- // Add import for this role
- addImport(context, bpelModel, conv, context.getRole());
-
- // Add import statements for partner roles
- java.util.List<Role> roles=conv.getRoles();
-
- for (int i=0; i < roles.size(); i++) {
- addImport(context, bpelModel, conv, roles.get(i));
- }
-
- // Add import for partner link types
- Import imp=new Import(bpelModel);
- imp.setLocation(context.getRole().getName()+"PartnerLinkTypes.wsdl");
- imp.setNamespace(roleNamespace);
- imp.setImportType("http://schemas.xmlsoap.org/wsdl/");
-
- bpelModel.getBPELProcess().addImport(imp, -1);
-
- // Add sequence to model
- bpelModel.getBPELProcess().setActivity(seq);
-
- } else if (context.getParent() instanceof Sequence) {
-
- // Create a scope
- Scope scope=new Scope(bpelModel);
-
- ((Sequence)context.getParent()).addActivity(scope, -1);
-
- // NOTE: Currently needs to be added after adding scope
- // to parent sequence, as otherwise the DOM element
- // associated with the 'seq' sequence becomes
- // disconnected from the actual document - due to
- // the fact that added elements are copied (in
- // turn due to an xml parser exception).
- scope.setActivity(seq);
- }
-
- // Process the activities within the conversation
- java.util.List<Activity> acts=conv.getBlock().getContents();
-
- Object parent=context.getParent();
-
- context.setParent(seq);
-
- for (int i=0; i < acts.size(); i++) {
- if ((acts.get(i) instanceof Definition) == false) {
- context.insert(model, acts.get(i), null);
- }
- }
-
- // Reset old parent
- context.setParent(parent);
-
- return(true);
- }
-
- /**
- * This method adds an import statement for the contract associated with the
- * supplied role.
- *
- * @param context The context
- * @param bpelModel The model
- * @param conv The conversation
- * @param role The role
- */
- protected void addImport(ModelChangeContext context, DefaultBPELLanguageModel bpelModel,
- Conversation conv, Role role) {
- if (role.getAnnotations().containsKey(Contract.class.getName())) {
- Contract contract=(Contract)role.getAnnotations().get(Contract.class.getName());
-
- boolean gen=false;
-
- for (int i=0; gen == false && i < contract.getInterfaces().size(); i++) {
- if (contract.getInterfaces().get(i).getMessageExchangePatterns().size() > 0) {
- gen = true;
- }
- }
-
- if (gen) {
- String fileName=Generator.getWSDLFileName(role,
- conv.getLocatedName().getName(), 0);
-
- Import imp=new Import(bpelModel);
-
- imp.setLocation(fileName);
- imp.setNamespace(contract.getNamespace());
- imp.setImportType("http://schemas.xmlsoap.org/wsdl/");
-
- bpelModel.getBPELProcess().addImport(imp, -1);
- }
- }
- }
-}
Added: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ModelChangeUtils.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ModelChangeUtils.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ModelChangeUtils.java 2009-11-08 15:03:11 UTC (rev 76)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.bpel.model.change;
+
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.contract.model.Contract;
+import org.scribble.conversation.model.*;
+
+/**
+ * Model change utilities.
+ */
+public class ModelChangeUtils {
+
+ /**
+ * This method checks whether the contracts need to be initialized.
+ *
+ * @param context The context
+ * @param conv The conversation
+ */
+ public static void initializeContracts(ModelChangeContext context, Conversation conv) {
+
+ if (context.getProperties().containsKey(Contract.class.getName()) == false) {
+ java.util.Map<String,Contract> contracts=new java.util.HashMap<String, Contract>();
+
+ if (conv.getLocatedName().getRole() != null) {
+ initializeRoleContract(conv.getLocatedName().getRole(), contracts);
+ }
+
+ for (Role r : conv.getRoles()) {
+ initializeRoleContract(r, contracts);
+ }
+
+ context.getProperties().put(Contract.class.getName(), contracts);
+ }
+ }
+
+ /**
+ * This method initializes the contract associated with the supplied role.
+ *
+ * @param role The role
+ * @param contracts The map of roles to contracts
+ */
+ protected static void initializeRoleContract(Role role, java.util.Map<String,Contract> contracts) {
+ if (role != null && role.getAnnotations().containsKey(Contract.class.getName())) {
+ contracts.put(role.getName(),
+ (Contract)role.getAnnotations().get(Contract.class.getName()));
+ }
+ }
+
+ /**
+ * This method returns the contract associated with the supplied role.
+ *
+ * @param contezt The context
+ * @param roleName The role name
+ * @return The contract, or null if not found
+ */
+ @SuppressWarnings("unchecked")
+ public static Contract getContract(ModelChangeContext context, String roleName) {
+ Contract ret=null;
+
+ if (context.getProperties().containsKey(Contract.class.getName())) {
+ java.util.Map<String,Contract> contracts=
+ (java.util.Map<String,Contract>)
+ context.getProperties().get(Contract.class.getName());
+
+ ret = contracts.get(roleName);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method updates the role mapping based on the supplied list of
+ * declaration bindings.
+ *
+ * @param context The context
+ * @param bindings The declaration bindings
+ */
+ @SuppressWarnings("unchecked")
+ public static void pushRoleContractMapping(ModelChangeContext context,
+ java.util.List<DeclarationBinding> bindings) {
+
+ if (context.getProperties().containsKey(Contract.class.getName())) {
+ java.util.Map<String,Contract> contracts=
+ (java.util.Map<String,Contract>)
+ context.getProperties().get(Contract.class.getName());
+
+ for (DeclarationBinding db : bindings) {
+ if (db.getDeclaration() instanceof Role) {
+ Contract c=contracts.remove(db.getDeclaration().getName());
+
+ if (c != null) {
+ contracts.put(db.getBoundName(), c);
+ }
+ }
+ }
+
+ }
+ }
+
+ /**
+ * This method resets the role mapping based on the supplied list of
+ * declaration bindings.
+ *
+ * @param context The context
+ * @param bindings The declaration bindings
+ */
+ @SuppressWarnings("unchecked")
+ public static void popRoleContractMapping(ModelChangeContext context,
+ java.util.List<DeclarationBinding> bindings) {
+
+ if (context.getProperties().containsKey(Contract.class.getName())) {
+ java.util.Map<String,Contract> contracts=
+ (java.util.Map<String,Contract>)
+ context.getProperties().get(Contract.class.getName());
+
+ for (DeclarationBinding db : bindings) {
+ if (db.getDeclaration() instanceof Role) {
+ Contract c=contracts.remove(db.getBoundName());
+
+ if (c != null) {
+ contracts.put(db.getDeclaration().getName(), c);
+ }
+ }
+ }
+
+ }
+ }
+}
Added: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/model/change/ModelChangeUtilsTest.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/model/change/ModelChangeUtilsTest.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/test/org/jboss/savara/tools/bpel/model/change/ModelChangeUtilsTest.java 2009-11-08 15:03:11 UTC (rev 76)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.bpel.model.change;
+
+import org.scribble.conversation.model.Conversation;
+import org.scribble.model.*;
+import org.scribble.model.change.DefaultModelChangeContext;
+import org.scribble.model.change.ModelChangeContext;
+import org.scribble.contract.model.*;
+
+import junit.framework.TestCase;
+
+public class ModelChangeUtilsTest extends TestCase {
+
+ private static final String MY_ROLE = "MyRole";
+ private static final String MY_OTHER_ROLE = "MyOtherRole";
+
+ public void testInitialiseContracts() {
+ ModelChangeContext context=new DefaultModelChangeContext(null, null);
+
+ Conversation conv=new Conversation();
+ LocatedName ln=new LocatedName();
+ Role r=new Role();
+ r.setName(MY_ROLE);
+
+ Contract c=new Contract();
+ r.getAnnotations().put(Contract.class.getName(), c);
+
+ ln.setRole(r);
+ conv.setLocatedName(ln);
+
+ ModelChangeUtils.initializeContracts(context, conv);
+
+ Contract c2=ModelChangeUtils.getContract(context, MY_ROLE);
+
+ if (c2 == null) {
+ fail("Contract not found");
+ }
+
+ if (c2 != c) {
+ fail("Contract not the same as the one stored");
+ }
+ }
+
+ public void testInitialiseContractsTwice() {
+ ModelChangeContext context=new DefaultModelChangeContext(null, null);
+
+ Conversation conv=new Conversation();
+ LocatedName ln=new LocatedName();
+ Role r=new Role();
+ r.setName(MY_ROLE);
+
+ Contract c=new Contract();
+ r.getAnnotations().put(Contract.class.getName(), c);
+
+ ln.setRole(r);
+ conv.setLocatedName(ln);
+
+ ModelChangeUtils.initializeContracts(context, conv);
+
+ Contract c2=new Contract();
+ r.getAnnotations().put(Contract.class.getName(), c2);
+
+ Contract c3=ModelChangeUtils.getContract(context, MY_ROLE);
+
+ if (c3 == null) {
+ fail("Contract not found");
+ }
+
+ if (c3 != c) {
+ fail("Contract not the same as the one stored");
+ }
+ }
+
+ public void testPushRoleContractMapping() {
+ ModelChangeContext context=new DefaultModelChangeContext(null, null);
+
+ Conversation conv=new Conversation();
+ LocatedName ln=new LocatedName();
+ Role r=new Role();
+ r.setName(MY_ROLE);
+
+ Contract c=new Contract();
+ r.getAnnotations().put(Contract.class.getName(), c);
+
+ ln.setRole(r);
+ conv.setLocatedName(ln);
+
+ ModelChangeUtils.initializeContracts(context, conv);
+
+ java.util.List<DeclarationBinding> bindings=new java.util.Vector<DeclarationBinding>();
+
+ DeclarationBinding db=new DeclarationBinding();
+ db.setDeclaration(r);
+ db.setBoundName(MY_OTHER_ROLE);
+ bindings.add(db);
+
+ ModelChangeUtils.pushRoleContractMapping(context, bindings);
+
+ Contract c2=ModelChangeUtils.getContract(context, MY_ROLE);
+ Contract c3=ModelChangeUtils.getContract(context, MY_OTHER_ROLE);
+
+ if (c2 != null) {
+ fail("Contract for "+MY_ROLE+" should be null");
+ }
+
+ if (c3 == null) {
+ fail("Contract for "+MY_OTHER_ROLE+" should NOT be null");
+ }
+
+ if (c3 != c) {
+ fail("Contract not the same as the one stored");
+ }
+ }
+
+ public void testPopRoleContractMapping() {
+ ModelChangeContext context=new DefaultModelChangeContext(null, null);
+
+ Conversation conv=new Conversation();
+ LocatedName ln=new LocatedName();
+ Role r=new Role();
+ r.setName(MY_ROLE);
+
+ Contract c=new Contract();
+ r.getAnnotations().put(Contract.class.getName(), c);
+
+ ln.setRole(r);
+ conv.setLocatedName(ln);
+
+ ModelChangeUtils.initializeContracts(context, conv);
+
+ java.util.List<DeclarationBinding> bindings=new java.util.Vector<DeclarationBinding>();
+
+ DeclarationBinding db=new DeclarationBinding();
+ db.setDeclaration(r);
+ db.setBoundName(MY_OTHER_ROLE);
+ bindings.add(db);
+
+ ModelChangeUtils.popRoleContractMapping(context, bindings);
+
+ Contract c2=ModelChangeUtils.getContract(context, MY_ROLE);
+ Contract c3=ModelChangeUtils.getContract(context, MY_OTHER_ROLE);
+
+ if (c2 == null) {
+ fail("Contract for "+MY_ROLE+" should NOT be null");
+ }
+
+ if (c3 != null) {
+ fail("Contract for "+MY_OTHER_ROLE+" should be null");
+ }
+
+ if (c2 != c) {
+ fail("Contract not the same as the one stored");
+ }
+ }
+}
More information about the savara-commits
mailing list