[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[stp-commits] r3325 - in org.eclipse.stp.sca/trunk/org.eclipse.stp.sca: . customsrc customsrc/org customsrc/org/eclipse customsrc/org/eclipse/stp customsrc/org/eclipse/stp/sca customsrc/org/eclipse/stp/sca/util

Author: sdrapeau
Date: 2009-09-15 12:50:14 -0400 (Tue, 15 Sep 2009)
New Revision: 3325

Added:
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/sca/
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/sca/util/
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/sca/util/ScaCompositeUtils.java
Modified:
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/.classpath
   org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/build.properties
Log:
Fix for bug #289474

Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/.classpath
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/.classpath	2009-09-15 16:11:27 UTC (rev 3324)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/.classpath	2009-09-15 16:50:14 UTC (rev 3325)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src"/>
+        <classpathentry kind="src" path="customsrc"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
 	<classpathentry kind="output" path="bin"/>

Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/build.properties
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/build.properties	2009-09-15 16:11:27 UTC (rev 3324)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/build.properties	2009-09-15 16:50:14 UTC (rev 3325)
@@ -26,5 +26,6 @@
                model/sca.ecore,\
                model/sca.genmodel
 jars.compile.order = .
-source.. = src/
+source.. = src/,\
+           customsrc/
 output.. = bin/

Added: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/sca/util/ScaCompositeUtils.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/sca/util/ScaCompositeUtils.java	                        (rev 0)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/sca/util/ScaCompositeUtils.java	2009-09-15 16:50:14 UTC (rev 3325)
@@ -0,0 +1,129 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+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.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.ecore.util.ExtendedMetaData;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.stp.sca.Composite;
+import org.eclipse.stp.sca.DocumentRoot;
+import org.eclipse.stp.sca.ScaPackage;
+
+/**
+ * @author Jamil Shaikh - RIM
+ */
+public class ScaCompositeUtils {
+
+	// Constructors
+
+	/**
+	 * Parse the Composite
+	 * 
+	 * @param IResource
+	 * @return Composite
+	 */
+	public static Composite getComposite(IResource compositeFile) {
+		Composite result = null;
+		// Create a resource set to hold the resources.
+		ResourceSet resourceSet = new ResourceSetImpl();
+		// Register the appropriate resource factory to handle all file
+		// extensions.
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
+						new ScaResourceFactoryImpl());
+		// Register the package to ensure it is available during loading.
+		resourceSet.getPackageRegistry().put(ScaPackage.eNS_URI,
+				ScaPackage.eINSTANCE);
+		URI uri = URI.createFileURI(compositeFile.getFullPath().toString());
+		try {
+			// Demand load resource for this file.
+			Resource resource = resourceSet.getResource(uri, true);
+			// Validate the contents of the loaded resource.
+			for (EObject eObject : resource.getContents()) {
+				Diagnostic diagnostic = Diagnostician.INSTANCE
+						.validate(eObject);
+				if (diagnostic.getSeverity() != Diagnostic.OK) {
+					// TODO
+
+				} else {
+					if (eObject instanceof DocumentRoot) {
+						result = ((DocumentRoot) eObject).getComposite();
+					}
+				}
+			}
+		} catch (RuntimeException exception) {
+			// TODO
+			exception.printStackTrace();
+		}
+		return result;
+	}
+
+	public static Composite getComposite(InputStream inputStream) {
+		Composite result = null;
+		// Create a resource set to hold the resources.
+		ResourceSet resourceSet = new ResourceSetImpl();
+		// Register the appropriate resource factory to handle all file
+		// extensions.
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
+						new ScaResourceFactoryImpl());
+		// Register the package to ensure it is available during loading.
+		resourceSet.getPackageRegistry().put(ScaPackage.eNS_URI,
+				ScaPackage.eINSTANCE);
+		try {
+			// Demand load resource for this file.
+			Resource resource = new ScaResourceImpl(null);
+			Map<String, Object> options = new HashMap<String, Object>();
+			options.put(XMLResource.OPTION_EXTENDED_META_DATA,
+					ExtendedMetaData.INSTANCE);
+			options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
+			options.put(XMLResource.OPTION_ZIP, Boolean.FALSE);
+			try {
+				resource.load(inputStream, options);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			// Validate the contents of the loaded resource.
+			for (EObject eObject : resource.getContents()) {
+				Diagnostic diagnostic = Diagnostician.INSTANCE
+						.validate(eObject);
+				if (diagnostic.getSeverity() != Diagnostic.OK) {
+					// TODO
+
+				} else {
+					if (eObject instanceof DocumentRoot) {
+						result = ((DocumentRoot) eObject).getComposite();
+					}
+				}
+			}
+		} catch (RuntimeException exception) {
+			// TODO
+			exception.printStackTrace();
+		}
+		return result;
+	}
+
+}


Property changes on: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca/customsrc/org/eclipse/stp/sca/util/ScaCompositeUtils.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain