[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[bpel-dev] patch6=add-rename-design-element-affect-source-tab
|
Hi Simon,
Please find attached the 6th patch for the
MultiTab-DomFacade branch.
The first step towards real EMF and DOM models synchronization
is done:
- renaming existent
elements and adding new ones in the design tab now reflect on the DOM model and
the source tab contents.
Classes added.
- org.eclipse.bpel.ui.BPELModelAdapter.
- org.eclipse.bpel.ui.BPELModelReconcileAdapter.
- org.eclipse.bpel.ui.util.BPELEditorUtil.
- org.eclipse.bpel.ui.util.BPELNodeAssociationManager.
All these classes were created from the corresponding
wsdl project classes. There is quite a lot of garbage in the code. I decided
not to clean it up until the next patch.
New dependencies.
- org.eclipse.bpel.model
now depends on org.eclipse.wst.xml.core and org.elipse.wst.sse.core.
- org.eclipse.bpel.ui
now depends on org.eclipse.wst.xsd.ui and org.eclipse.wst.wsdl.ui
Known bugs and limitations.
- Do not edit source
in the source tab and then save the file. Changes in the DOM model don’t
affect EMF model.
- Elements are added
into the DOM model (and thus in the source tab) without the name attribute.
- Renaming just added elements
in the design tab doesn’t affect the corresponding nodes in the
source tab until the file is saved.
- The source tab
content is not formatted after adding new elements in the design tab.
Thanks,
Vitaly.
|
### Eclipse Workspace Patch 1.0
#P org.eclipse.bpel.model
Index: src/org/eclipse/bpel/model/resource/BPELWriter.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/resource/BPELWriter.java,v
retrieving revision 1.32
diff -u -r1.32 BPELWriter.java
--- src/org/eclipse/bpel/model/resource/BPELWriter.java 20 Apr 2007 23:31:44 -0000 1.32
+++ src/org/eclipse/bpel/model/resource/BPELWriter.java 20 Jul 2007 17:10:19 -0000
@@ -351,6 +351,16 @@
}
}
+ public BPELWriter() {
+ }
+
+ public BPELWriter(BPELResource resource, Document document) {
+ this();
+ this.bpelResource = resource;
+ this.document = document;
+ bpelNamespacePrefixManager = new NamespacePrefixManager(resource);
+ }
+
/**
* Convert the BPEL model to an XML DOM model and then write the DOM model
* to the output stream.
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.model/META-INF/MANIFEST.MF,v
retrieving revision 1.7.2.1
diff -u -r1.7.2.1 MANIFEST.MF
--- META-INF/MANIFEST.MF 17 Jul 2007 13:42:50 -0000 1.7.2.1
+++ META-INF/MANIFEST.MF 20 Jul 2007 17:10:17 -0000
@@ -12,7 +12,9 @@
org.eclipse.xsd,
org.eclipse.wst.wsdl,
org.apache.xerces,
- javax.wsdl
+ javax.wsdl,
+ org.eclipse.wst.xml.core,
+ org.eclipse.wst.sse.core
Eclipse-LazyStart: true
Export-Package: org.eclipse.bpel.model,
org.eclipse.bpel.model.adapters,
#P org.eclipse.bpel.ui
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/META-INF/MANIFEST.MF,v
retrieving revision 1.9.2.2
diff -u -r1.9.2.2 MANIFEST.MF
--- META-INF/MANIFEST.MF 17 Jul 2007 13:42:49 -0000 1.9.2.2
+++ META-INF/MANIFEST.MF 20 Jul 2007 17:10:21 -0000
@@ -24,7 +24,9 @@
org.eclipse.bpel.wsil.model,
org.eclipse.wst.sse.ui,
org.eclipse.wst.sse.core,
- javax.wsdl
+ javax.wsdl,
+ org.eclipse.wst.xsd.ui,
+ org.eclipse.wst.wsdl.ui
Eclipse-LazyStart: true
Export-Package: org.eclipse.bpel.ui,
org.eclipse.bpel.ui.actions,
Index: src/org/eclipse/bpel/ui/commands/SetNameCommand.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/commands/SetNameCommand.java,v
retrieving revision 1.1
diff -u -r1.1 SetNameCommand.java
--- src/org/eclipse/bpel/ui/commands/SetNameCommand.java 29 Nov 2005 18:51:06 -0000 1.1
+++ src/org/eclipse/bpel/ui/commands/SetNameCommand.java 20 Jul 2007 17:10:22 -0000
@@ -10,10 +10,17 @@
*******************************************************************************/
package org.eclipse.bpel.ui.commands;
+import org.eclipse.bpel.model.ExtensibleElement;
import org.eclipse.bpel.ui.IBPELUIConstants;
import org.eclipse.bpel.ui.adapters.INamedElement;
+import org.eclipse.bpel.ui.uiextensionmodel.StartNode;
+import org.eclipse.bpel.ui.util.BPELEditorUtil;
import org.eclipse.bpel.ui.util.BPELUtil;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.w3c.dom.Element;
/**
@@ -22,6 +29,9 @@
* Process objects.
*/
public class SetNameCommand extends SetCommand {
+
+ private class MyBPELWriter extends org.eclipse.bpel.model.resource.BPELWriter {
+ }
public String getDefaultLabel() { return IBPELUIConstants.CMD_EDIT_NAME; }
@@ -41,5 +51,10 @@
public void set(Object o) {
INamedElement namedElement = (INamedElement)BPELUtil.adapt(target, INamedElement.class);
namedElement.setName(target, (String)o);
+
+ Element element = BPELEditorUtil.getInstance().getElementForObject(target);
+ if (element != null) {
+ element.setAttribute("name", (String)o); //$NON-NLS-1$
+ }
}
}
Index: src/org/eclipse/bpel/ui/commands/InsertInContainerCommand.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/commands/InsertInContainerCommand.java,v
retrieving revision 1.1
diff -u -r1.1 InsertInContainerCommand.java
--- src/org/eclipse/bpel/ui/commands/InsertInContainerCommand.java 29 Nov 2005 18:51:05 -0000 1.1
+++ src/org/eclipse/bpel/ui/commands/InsertInContainerCommand.java 20 Jul 2007 17:10:22 -0000
@@ -19,12 +19,25 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osgi.util.NLS;
+import org.w3c.dom.Element;
+
/**
* This command is used to add a child into a parent object which supports IContainer.
*/
public class InsertInContainerCommand extends AutoUndoCommand {
+ private class MyBPELWriter extends org.eclipse.bpel.model.resource.BPELWriter {
+ private MyBPELWriter(org.eclipse.bpel.model.resource.BPELResource bpelResource, org.w3c.dom.Document document) {
+ super(bpelResource, document);
+ }
+
+ public Element activity2XML(org.eclipse.bpel.model.Activity activity) {
+ //just make the method public
+ return super.activity2XML(activity);
+ }
+ }
+
protected EObject child, parent, before;
protected Rectangle rect;
@@ -48,6 +61,19 @@
public void doExecute() {
IContainer container = (IContainer)BPELUtil.adapt(parent, IContainer.class);
container.addChild(parent, child, before);
+
+ Element parentElement = org.eclipse.bpel.ui.util.BPELEditorUtil.getInstance().getElementForObject(parent);
+ Element beforeElement = null;
+ if (before != null) {
+ beforeElement = org.eclipse.bpel.ui.util.BPELEditorUtil.getInstance().getElementForObject(before);
+ }
+
+ MyBPELWriter writer = new MyBPELWriter((org.eclipse.bpel.model.resource.BPELResource)(parent.eResource()),
+ parentElement.getOwnerDocument());
+
+ Element childElement = writer.activity2XML(((org.eclipse.bpel.model.Activity)child));
+
+ parentElement.insertBefore(childElement, beforeElement);
}
public EObject getChild() { return child; }
Index: src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/Attic/BPELMultipageEditorPart.java,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 BPELMultipageEditorPart.java
--- src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java 17 Jul 2007 13:42:49 -0000 1.1.2.4
+++ src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java 20 Jul 2007 17:10:22 -0000
@@ -304,10 +304,6 @@
if (selectedNodeElement != null) {
StructuredSelection nodeSelection = new StructuredSelection(selectedNodeElement);
getTextEditor().getSelectionProvider().setSelection(nodeSelection);
- //int charStart = ((Number)selectedNodeElement.getUserData("location.charStart")).intValue();
- //-1 to point to the '<' literal
- //TextSelection textSelection = new TextSelection(charStart - 1, 0);
- //getTextEditor().getSelectionProvider().setSelection(textSelection);
}
} catch (Exception e) {
e.printStackTrace();
@@ -456,8 +452,9 @@
* @see org.eclipse.ui.IEditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
*/
public void doSave(IProgressMonitor progressMonitor) {
- fDesignViewer.doSave(progressMonitor);
+ //fDesignViewer should be saved the last to avoid problems with SynchronizationManager
fTextEditor.doSave(progressMonitor);
+ fDesignViewer.doSave(progressMonitor);
}
/*
@@ -857,6 +854,9 @@
reader.read(bpelResource, file, fDesignViewer.getResourceSet());
process = reader.getProcess();
+ BPELModelReconcileAdapter bpelModelReconcileAdapter
+ = new BPELModelReconcileAdapter (structuredDocument, process);
+
if (getEditDomain() != null) {
((BPELEditDomain)getEditDomain()).setProcess(getProcess());
}
Index: src/org/eclipse/bpel/ui/BPELModelAdapter.java
===================================================================
RCS file: src/org/eclipse/bpel/ui/BPELModelAdapter.java
diff -N src/org/eclipse/bpel/ui/BPELModelAdapter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/bpel/ui/BPELModelAdapter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,169 @@
+package org.eclipse.bpel.ui;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.wsdl.Definition;
+import org.eclipse.wst.wsdl.WSDLFactory;
+import org.eclipse.wst.wsdl.internal.impl.DefinitionImpl;
+import org.eclipse.wst.wsdl.internal.util.WSDLResourceFactoryImpl;
+import org.eclipse.wst.wsdl.util.WSDLResourceImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xsd.ui.internal.util.ModelReconcileAdapter;
+import org.eclipse.wst.xsd.ui.internal.util.XSDSchemaLocationResolverAdapterFactory;
+import org.eclipse.xsd.util.XSDResourceImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class BPELModelAdapter implements INodeAdapter
+{
+ protected ResourceSet resourceSet;
+ protected Process process;
+ private ModelReconcileAdapter modelReconcileAdapter;
+
+ public Process getProcess()
+ {
+ return process;
+ }
+
+ public void setProcess(Process process)
+ {
+ this.process = process;
+ }
+
+ public boolean isAdapterForType(Object type)
+ {
+ return type == BPELModelAdapter.class;
+ }
+
+ public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos)
+ {
+ }
+
+ /*public Definition createDefinition(final Document document)
+ {
+ try
+ {
+ IDOMNode domNode = (IDOMNode) document;
+ String baseLocation = "blankWSDL.wsdl"; //$NON-NLS-1$
+ if (domNode != null)
+ {
+ baseLocation = domNode.getModel().getBaseLocation();
+ }
+ else if (document instanceof IDOMNode)
+ {
+ IDOMModel domModel = ((IDOMNode) document).getModel();
+ baseLocation = domModel.getBaseLocation();
+ }
+ resourceSet = new ResourceSetImpl();
+
+ //FIXME do we need it?
+ //resourceSet.getAdapterFactories().add(new WSDLModelLocatorAdapterFactory());
+ //resourceSet.getAdapterFactories().add(new XSDSchemaLocationResolverAdapterFactory());
+ // TODO.. .revist the best approach to obtain a URI from the SSE model
+ //
+ URI uri = null;
+ if (baseLocation.startsWith("/")) //$NON-NLS-1$
+ {
+ uri = URI.createPlatformResourceURI(baseLocation);
+ }
+ else
+ {
+ uri = URI.createFileURI(baseLocation);
+ }
+ definition = WSDLFactory.eINSTANCE.createDefinition();
+ definition.setDocumentBaseURI(uri.toString());
+ definition.setDocument(document);
+
+ WSDLResourceFactoryImpl resourceFactory = new WSDLResourceFactoryImpl();
+ Resource resource = resourceFactory.createResource(uri);
+ resourceSet.getResources().add(resource);
+ resource.getContents().add(definition);
+ resource.setModified(false);
+
+ IRunnableWithProgress setElementOperation = new IRunnableWithProgress()
+ {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
+ {
+ // Use the animated flavour as we don't know beforehand how many ticks we need.
+ // The task name will be displayed by the code in WSDLResourceImpl and XSDResourceImpl.
+
+ monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
+
+ Map loadOptions = resourceSet.getLoadOptions();
+
+ loadOptions.put(WSDLResourceImpl.WSDL_PROGRESS_MONITOR, monitor);
+ loadOptions.put(XSDResourceImpl.XSD_PROGRESS_MONITOR, monitor);
+
+ definition.setElement(document.getDocumentElement());
+ ((DefinitionImpl) definition).reconcileReferences(true);
+
+ loadOptions.remove(WSDLResourceImpl.WSDL_PROGRESS_MONITOR);
+ loadOptions.remove(XSDResourceImpl.XSD_PROGRESS_MONITOR);
+ }
+ };
+
+ IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
+ try
+ {
+ progressService.busyCursorWhile(setElementOperation);
+ }
+ catch (InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+
+ // attach an adapter to keep the WSDL model and DOM in sync
+ //
+ modelReconcileAdapter = new WSDLModelReconcileAdapter(document, definition);
+ domNode.getModel().addModelStateListener(modelReconcileAdapter);
+
+ // TODO... CS : revisit this line
+ // currently this is used to associate a 'type' system with the definition
+ // I suspect that this could be made a whole lot more simple
+ //
+ WSDLEditorUtil.getInstance().setTypeSystemProvider(definition, new ExtensibleTypeSystemProvider());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ return definition;
+ }*/
+
+ public ModelReconcileAdapter getModelReconcileAdapter()
+ {
+ return modelReconcileAdapter;
+ }
+
+ public static BPELModelAdapter lookupOrCreateModelAdapter(Document document)
+ {
+ BPELModelAdapter adapter = null;
+ if (document instanceof INodeNotifier)
+ {
+ INodeNotifier notifier = (INodeNotifier)document;
+ adapter = (BPELModelAdapter)notifier.getAdapterFor(BPELModelAdapter.class);
+ if (adapter == null)
+ {
+ adapter = new BPELModelAdapter();
+ notifier.addAdapter(adapter);
+ }
+ }
+ return adapter;
+ }
+}
Index: src/org/eclipse/bpel/ui/util/BPELNodeAssociationManager.java
===================================================================
RCS file: src/org/eclipse/bpel/ui/util/BPELNodeAssociationManager.java
diff -N src/org/eclipse/bpel/ui/util/BPELNodeAssociationManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/bpel/ui/util/BPELNodeAssociationManager.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,36 @@
+package org.eclipse.bpel.ui.util;
+
+import org.eclipse.wst.wsdl.ui.internal.util.NodeAssociationManager;
+import org.eclipse.wst.wsdl.ui.internal.extensions.INodeAssociationProvider;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class BPELNodeAssociationManager extends NodeAssociationManager {
+ protected INodeAssociationProvider wsdlProvider;
+ protected INodeAssociationProvider xsdProvider;
+
+ public BPELNodeAssociationManager() {
+ //FIXME init bpelProvider here
+ super();
+ }
+
+ protected INodeAssociationProvider getAppicableProvider(Object object) {
+ //FIXME add code for returning bpelProvider here
+ return super.getAppicableProvider(object);
+ }
+
+ public Object getModelObjectForNode(Object rootObject, Element targetNode) {
+ //FIXME try super; delete is super is OK
+ return super.getModelObjectForNode(rootObject, targetNode);
+ }
+
+ public Node getNode(Object modelObject) {
+ //FIXME try super; delete is super is OK
+ return super.getNode(modelObject);
+ }
+
+ protected Element[] getParentElementChain(Element element) {
+ //FIXME try super; delete is super is OK
+ return super.getParentElementChain(element);
+ }
+}
Index: src/org/eclipse/bpel/ui/util/BPELEditorUtil.java
===================================================================
RCS file: src/org/eclipse/bpel/ui/util/BPELEditorUtil.java
diff -N src/org/eclipse/bpel/ui/util/BPELEditorUtil.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/bpel/ui/util/BPELEditorUtil.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,252 @@
+package org.eclipse.bpel.ui.util;
+
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerFactory;
+
+import org.eclipse.bpel.model.util.BPELConstants;
+
+import org.eclipse.wst.wsdl.Definition;
+import org.eclipse.wst.wsdl.ExtensibleElement;
+import org.eclipse.wst.wsdl.MessageReference;
+import org.eclipse.wst.wsdl.Operation;
+import org.eclipse.wst.wsdl.PortType;
+import org.eclipse.wst.wsdl.Types;
+import org.eclipse.wst.wsdl.WSDLElement;
+import org.eclipse.wst.wsdl.ui.internal.extensions.ExtensibleTypeSystemProvider;
+import org.eclipse.wst.wsdl.ui.internal.extensions.ITypeSystemProvider;
+import org.eclipse.wst.wsdl.util.WSDLConstants;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class BPELEditorUtil extends BPELConstants
+{
+ protected static BPELEditorUtil instance;
+ protected BPELNodeAssociationManager nodeAssociationManager = new BPELNodeAssociationManager();
+
+ protected HashMap elementNameToTypeMap = new HashMap();
+
+ public static final int ELEMENT = 14;
+ public static final int TYPE = 15;
+
+ public static BPELEditorUtil getInstance()
+ {
+ if (instance == null)
+ {
+ instance = new BPELEditorUtil();
+ }
+ return instance;
+ }
+
+ public BPELEditorUtil()
+ {
+ //FIXME add bpel tage here
+ /*elementNameToTypeMap.put(BINDING_ELEMENT_TAG, new Integer(BINDING));
+ elementNameToTypeMap.put(DEFINITION_ELEMENT_TAG, new Integer(DEFINITION));
+ elementNameToTypeMap.put(DOCUMENTATION_ELEMENT_TAG, new Integer(DOCUMENTATION));
+ elementNameToTypeMap.put(FAULT_ELEMENT_TAG, new Integer(FAULT));
+ elementNameToTypeMap.put(IMPORT_ELEMENT_TAG, new Integer(IMPORT));
+ elementNameToTypeMap.put(INPUT_ELEMENT_TAG, new Integer(INPUT));
+ elementNameToTypeMap.put(MESSAGE_ELEMENT_TAG, new Integer(MESSAGE));
+ elementNameToTypeMap.put(OPERATION_ELEMENT_TAG, new Integer(OPERATION));
+ elementNameToTypeMap.put(OUTPUT_ELEMENT_TAG, new Integer(OUTPUT));
+ elementNameToTypeMap.put(PART_ELEMENT_TAG, new Integer(PART));
+ elementNameToTypeMap.put(PORT_ELEMENT_TAG, new Integer(PORT));
+ elementNameToTypeMap.put(PORT_TYPE_ELEMENT_TAG, new Integer(PORT_TYPE));
+ elementNameToTypeMap.put(SERVICE_ELEMENT_TAG, new Integer(SERVICE));
+ elementNameToTypeMap.put(TYPES_ELEMENT_TAG, new Integer(TYPES));*/
+ }
+
+ public int getWSDLType(Element element)
+ {
+ int result = -1;
+
+ Integer integer = (Integer)elementNameToTypeMap.get(element.getLocalName());
+ if (integer != null)
+ {
+ result = integer.intValue();
+ }
+ return result;
+ }
+
+ protected List getParentElementChain(Element element)
+ {
+ List list = new ArrayList();
+ while (element != null)
+ {
+ list.add(0, element);
+ Node node = element.getParentNode();
+ element = (node != null && node.getNodeType() == Node.ELEMENT_NODE) ? (Element)node : null;
+ }
+ return list;
+ }
+
+ public Object findModelObjectForElement(Definition definition, Element targetElement)
+ {
+ Object o = nodeAssociationManager.getModelObjectForNode(definition, targetElement);
+ return o;
+ }
+
+ public Element getElementForObject(Object o)
+ {
+ return ((WSDLElement)o).getElement();
+ }
+
+ public Node getNodeForObject(Object o)
+ {
+ return nodeAssociationManager.getNode(o);
+ }
+
+ // Provide a mapping between Definitions and ITypeSystemProviders
+// private Hashtable typeSystemProviders = new Hashtable();
+ private ITypeSystemProvider typeSystemProvider;
+
+ public ITypeSystemProvider getTypeSystemProvider(Definition definition)
+ {
+ if (typeSystemProvider == null) {
+ typeSystemProvider = new ExtensibleTypeSystemProvider();
+ }
+ return typeSystemProvider;
+ }
+
+ public void setTypeSystemProvider(Definition definition, ITypeSystemProvider typeSystemProvider)
+ {
+ // typeSystemProviders.put(definition,typeSystemProvider);
+ }
+
+/* public static QName createQName(Definition definition, String prefixedName)
+ {
+ QName qname = null;
+ if (prefixedName != null)
+ {
+ int index = prefixedName.indexOf(":"); //$NON-NLS-1$
+// String prefix = (index == -1) ? null : prefixedName.substring(0, index);
+ String prefix = (index == -1) ? "" : prefixedName.substring(0, index);
+ if (prefix != null)
+ {
+ String namespace = definition.getNamespace(prefix);
+ if (namespace != null)
+ {
+ String localPart = prefixedName.substring(index + 1);
+ qname = new QName(namespace, localPart);
+ }
+ }
+ }
+ return qname;
+ }*/
+
+ public List getExtensibilityElementNodes(ExtensibleElement extensibleElement)
+ {
+ // For Types, I need to get all the schemas
+ if (extensibleElement instanceof Types)
+ {
+ Types xsdEE = (Types)extensibleElement;
+ return xsdEE.getSchemas();
+ }
+
+ return extensibleElement.getEExtensibilityElements();
+ }
+
+ /*
+ * Returns a list of 'children' of the given object model (WSDLElement).
+ */
+ public static List getModelGraphViewChildren(Object object) {
+ List childList = new ArrayList();
+
+ if (object instanceof PortType) {
+ PortType portType = (PortType) object;
+ childList.addAll(portType.getOperations());
+ }
+ else if (object instanceof Operation) {
+ Operation operation = (Operation) object;
+
+ if (operation.getEInput() != null) {
+ childList.add(operation.getEInput());
+ }
+ if (operation.getEOutput() != null) {
+ childList.add(operation.getEOutput());
+ }
+ childList.addAll(operation.getFaults().values());
+ }
+ else if (object instanceof MessageReference) {
+ MessageReference messageReference = (MessageReference) object;
+ childList.add(messageReference.getEMessage());
+ }
+
+ return childList;
+ }
+
+ /*public static String getTargetNamespaceURIForSchema(String uri)
+ {
+ String result = null;
+ try
+ {
+ URL url = new URL(uri);
+ InputStream inputStream = url.openStream();
+ result = WSDLEditorUtil.getTargetNamespaceURIForSchema(inputStream);
+ }
+ catch (Exception e)
+ {
+ }
+ return result;
+ }*/
+
+ /*public static String getTargetNamespaceURIForSchema(InputStream input)
+ {
+ TargetNamespaceURIContentHandler handler = new TargetNamespaceURIContentHandler();
+ ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(WSDLEditorUtil.class.getClassLoader());
+ // Line below is a hack to get XMLReader working
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ try
+ {
+ XMLReader reader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
+ reader.setContentHandler(handler);
+ reader.parse(new InputSource(input));
+ }
+ catch (Exception e)
+ {
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(prevClassLoader);
+ }
+ return handler.targetNamespaceURI;
+ } */
+
+ /*protected static class TargetNamespaceURIContentHandler extends DefaultHandler
+ {
+ public String targetNamespaceURI;
+
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
+ {
+ if (localName.equals("schema") || localName.equals("definitions")) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ int nAttributes = attributes.getLength();
+ for (int i = 0; i < nAttributes; i++)
+ {
+ if (attributes.getLocalName(i).equals("targetNamespace")) //$NON-NLS-1$
+ {
+ targetNamespaceURI = attributes.getValue(i);
+ break;
+ }
+ }
+ }
+ // todo there's a ice way to do this I'm sure
+ // here I intentially cause an exception...
+ String x = null;
+ x.length();
+ }
+ }*/
+}
Index: src/org/eclipse/bpel/ui/BPELModelReconcileAdapter.java
===================================================================
RCS file: src/org/eclipse/bpel/ui/BPELModelReconcileAdapter.java
diff -N src/org/eclipse/bpel/ui/BPELModelReconcileAdapter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/bpel/ui/BPELModelReconcileAdapter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,136 @@
+package org.eclipse.bpel.ui;
+
+import org.eclipse.bpel.model.Process;
+
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.wsdl.Definition;
+import org.eclipse.wst.wsdl.internal.impl.DefinitionImpl;
+import org.eclipse.wst.wsdl.internal.impl.WSDLElementImpl;
+import org.eclipse.wst.wsdl.internal.impl.XSDSchemaExtensibilityElementImpl;
+import org.eclipse.wst.wsdl.util.WSDLConstants;
+import org.eclipse.wst.xsd.ui.internal.util.ModelReconcileAdapter;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.impl.XSDSchemaImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+class BPELModelReconcileAdapter extends ModelReconcileAdapter
+{
+ protected Process process;
+
+ public BPELModelReconcileAdapter(Document document, Process process)
+ {
+ super(document);
+ this.process = process;
+ }
+
+ // This method is clever enough to deal with 'bad' documents that happen
+ // to have more than one root element. It picks of the first 'matching' element.
+ //
+ // TODO (cs) why aren't we calling this from the WSDLModelAdapter when the model is initialized?
+ //
+ private Element getProcessElement(Document document)
+ {
+ Element processElement = null;
+ for (Node node = document.getFirstChild(); node != null; node = node.getNextSibling())
+ {
+ if (node.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element element = (Element)node;
+ /*if (WSDLEditorUtil.getInstance().getWSDLType(element) == WSDLConstants.DEFINITION)
+ {
+ definitionElement = element;
+ break;
+ }*/
+ }
+ }
+ return processElement;
+ }
+
+ protected void handleNodeChanged(Node node)
+ {
+ if (node instanceof Element) {
+ reconcileModelObjectForElement((Element)node);
+ } else if (node instanceof Document) {
+ // The document changed so we may need to fix up the
+ // definition's root element
+ Document document = (Document)node;
+ Element processElement = getProcessElement(document);
+ /*if (definitionElement != null && definitionElement != process.getElement())
+ {
+ // here we handle the case where a new 'definition' element was added
+ //(e.g. the file was totally blank and then we type in the root element)
+ // See Bug 5366
+ //
+ if (definitionElement.getLocalName().equals(WSDLConstants.DEFINITION_ELEMENT_TAG))
+ {
+ //System.out.println("****** Setting new definition");
+ process.setElement(definitionElement);
+ }
+ }
+ else if (definitionElement != null)
+ {
+ // handle the case where the definition element's content has changed
+ //
+ ((ProcessImpl)process).elementChanged(definitionElement);
+ }
+ else if (definitionElement == null)
+ {
+ // if there's no definition element clear out the WSDL
+ //
+ ((ProcessImpl)process).removeAll();
+
+ // The removeAll() call does not remove namespaces as well and the model
+ // does not reconcile well in this case. Also reset the definition name and target
+ // namespace.
+
+ process.getNamespaces().clear();
+ process.setQName(null);
+ process.setTargetNamespace(null);
+
+ // Reset the document because removeAll() sets the document to null as well.
+ process.setDocument(document);
+ }*/
+ }
+ }
+
+ private void reconcileModelObjectForElement(Element element)
+ {
+ Object modelObject = null;//WSDLEditorUtil.getInstance().findModelObjectForElement(process, element);
+ if (modelObject != null)
+ {
+ if (modelObject instanceof XSDSchemaExtensibilityElementImpl)
+ {
+ XSDSchemaExtensibilityElementImpl ee = (XSDSchemaExtensibilityElementImpl)modelObject;
+ ((XSDSchemaImpl)ee.getSchema()).elementChanged(element);
+ ee.elementChanged(element);
+ }
+ else if (modelObject instanceof WSDLElementImpl)
+ {
+ ((WSDLElementImpl)modelObject).elementChanged(element);
+ }
+ else if (modelObject instanceof XSDConcreteComponent)
+ {
+ ((XSDConcreteComponent)modelObject).elementChanged(element);
+ }
+ }
+ }
+
+ public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty)
+ {
+ if (!isDirty)
+ {
+ // cs : At this time (when a save occurs) it's a good opportunity
+ // to update the model to ensure it's in sync with the source.
+ // That way if the incremental sync between DOM and model has gotten
+ // the model out of whack we'll be able to put things right at this point.
+ //
+ // TODO (cs) need to do more to ensure model is sync'd up properly
+
+ //FIXME uncomment
+ //((ProcessImpl)process).reconcileReferences(true);
+ }
+ }
+}