geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From de...@apache.org
Subject svn commit: r952535 [22/26] - in /geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins: org.apache.geronimo.j2ee.v11.jaxbmodel/ org.apache.geronimo.j2ee.v11.jaxbmodel/META-INF/ org.apache.geronimo.j2ee.v11.jaxbmodel/src/main/java/org/apache/geronimo...
Date Tue, 08 Jun 2010 04:40:28 GMT
Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryCreationOperation.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryCreationOperation.java?rev=952535&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryCreationOperation.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryCreationOperation.java Tue Jun  8 04:40:16 2010
@@ -0,0 +1,440 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v21.core.operations;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.status.DeploymentStatus;
+import javax.enterprise.deploy.spi.status.ProgressObject;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.st.v21.core.Activator;
+import org.apache.geronimo.st.v21.core.GeronimoServerBehaviourDelegate;
+import org.apache.geronimo.st.v21.core.GeronimoUtils;
+import org.apache.geronimo.st.v21.core.commands.DeploymentCommandFactory;
+import org.apache.geronimo.st.core.internal.Trace;
+import org.apache.geronimo.st.core.operations.ISharedLibEntryCreationDataModelProperties;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.internal.deployables.J2EEFlexProjDeployable;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.internal.ProgressUtil;
+import org.eclipse.wst.server.core.model.ModuleDelegate;
+
+/**
+ * @version $Rev: 817996 $ $Date: 2009-09-23 16:04:12 +0800 (Wed, 23 Sep 2009) $
+ */
+public class SharedLibEntryCreationOperation extends AbstractDataModelOperation implements ISharedLibEntryCreationDataModelProperties {
+	
+	private TargetModuleID sharedLibTarget;
+	private IServer server;
+	private IProgressMonitor monitor;
+	private IPath sharedLibLocation;
+	private static final IPath TEMP_LOCATION = Activator.getDefault().getStateLocation().append("shared-lib-temp");
+
+	public SharedLibEntryCreationOperation() {
+	}
+
+	/**
+	 * @param model
+	 */
+	public SharedLibEntryCreationOperation(IDataModel model) {
+		super(model);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
+	 *      org.eclipse.core.runtime.IAdaptable)
+	 */
+	public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+		Trace.trace(Trace.INFO, ">> SharedLibEntryCreationOperation.execute()");
+		
+		this.monitor = ProgressUtil.getMonitorFor(monitor);
+		this.monitor.beginTask("Processing in-place shared libraries.", 100);
+		
+		IModule[] modules = (IModule[]) model.getProperty(MODULES);
+		this.server = (IServer) model.getProperty(SERVER);
+		
+		HashMap<File, File> addList = new HashMap<File, File>();
+		List<File> deleteList = new ArrayList<File>();
+		
+		try {
+			String sharedLibPath = getSharedLibPath();
+			if(sharedLibPath == null) 
+				return Status.CANCEL_STATUS;
+			
+			sharedLibLocation = server.getRuntime().getLocation().append(sharedLibPath);
+			
+			for(int i = 0; i < modules.length; i++) {
+				IModule module = modules[i];
+				IProject project = module.getProject();
+				
+				File dummyJarFile = sharedLibLocation.append(project.getName() + ".eclipse.jar").toFile();
+				// delete the dummy jar if module no longer associated with server
+				if (!ServerUtil.containsModule(server, module, monitor) && dummyJarFile.exists()) {
+					deleteList.add(dummyJarFile);
+				} else {
+					HashSet entries = new HashSet();
+					J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module.loadAdapter(J2EEFlexProjDeployable.class, null);
+					if(GeronimoUtils.isEarModule(module)) {
+						IModule[] childModules = j2eeModule.getChildModules();
+						for(int j = 0; j < modules.length; j++) {
+							entries.addAll(processModule(childModules[i]));
+						}
+					} else {
+						entries.addAll(processModule(module));
+					}
+
+					// regen the jar only if required
+					if (regenerate(dummyJarFile, entries)) {
+						TEMP_LOCATION.toFile().mkdirs();
+						File temp = TEMP_LOCATION.append(project.getName() + ".eclipse.jar").toFile();
+						Trace.trace(Trace.INFO, "Updating external sharedlib entries for " + module.getName());
+						if(temp.exists())
+							delete(temp);
+						Manifest manifest = new Manifest();
+						Attributes attributes = manifest.getMainAttributes();
+						attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+						attributes.put(Attributes.Name.CLASS_PATH, getCPEntriesAsString(entries));
+						JarOutputStream os = new JarOutputStream(new FileOutputStream(temp), manifest);
+						os.flush();
+						os.close();
+						addList.put(temp, dummyJarFile);
+					}
+				}
+			}
+			
+			updateAndRecycleSharedLib(addList, deleteList);
+			
+		}catch (CoreException e){
+			IStatus status = e.getStatus();
+			Trace.trace(Trace.SEVERE, status.getMessage(), e);
+			throw new ExecutionException(status.getMessage(), e);
+		}catch (Exception e) {
+			Trace.trace(Trace.SEVERE, "Failure in updating shared library.", e);
+			throw new ExecutionException("Failure in updating shared library", e);
+		} finally {
+			monitor.done();
+		}
+		
+		Trace.trace(Trace.INFO, "<< SharedLibEntryCreationOperation.execute()");
+		return Status.OK_STATUS;
+	}
+	
+	private void updateAndRecycleSharedLib(HashMap addList, List deleteList) throws Exception {
+		if(addList.size() > 0 || deleteList.size() > 0) {
+			stopSharedLib();
+			for(int i = 0; i < deleteList.size(); i++) {
+				File file = (File) deleteList.get(i);
+				delete(file);
+			}
+			Iterator i = addList.keySet().iterator();
+			while(i.hasNext()) {
+				File src = (File) i.next();
+				File dest = (File) addList.get(src);
+				if(dest.exists()) {
+					delete(dest);
+				}
+				copy(src, dest);
+			}
+			startSharedLib();
+		}
+	}
+	
+	private void copy(File src, File dest) throws Exception {
+		try {
+			InputStream in = new FileInputStream(src);
+			OutputStream out = new FileOutputStream(dest);
+			byte[] buf = new byte[1024];
+			int len;
+			while ((len = in.read(buf)) > 0) {
+				out.write(buf, 0, len);
+			}
+			in.close();
+			out.close();
+		} catch (Exception e) {
+			throw e;
+		}
+		Trace.trace(Trace.INFO, "Created " + dest.getAbsolutePath());
+	}
+
+	private String getSharedLibPath() throws Exception {
+		// locate the path of the first sharedlib library folder
+		GeronimoServerBehaviourDelegate gsDelegate = (GeronimoServerBehaviourDelegate) server.getAdapter(GeronimoServerBehaviourDelegate.class);
+		MBeanServerConnection connection = gsDelegate.getServerConnection();
+		Set result = connection.queryMBeans(new ObjectName("*:j2eeType=GBean,name=SharedLib,*"), null);
+		if (!result.isEmpty()) {
+			ObjectInstance instance = (ObjectInstance) result.toArray()[0];
+			String[] libDirs = (String[]) connection.getAttribute(instance.getObjectName(),"libDirs");
+			if (libDirs != null && libDirs.length > 0) {
+				return libDirs[0];
+			}
+		}
+		return null;
+	}
+	
+	private HashSet processModule(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, "SharedLibEntryCreationOperation.process() " + module.getName());
+
+		IProject project = module.getProject();
+		// filter the cp entries needed to be added to the dummy shared lib
+		// jar
+		HashSet entries = new HashSet();
+		processJavaProject(project, entries, false);
+
+		// add output locations of referenced projects excluding non-child
+		// projects
+		ModuleDelegate delegate = (ModuleDelegate) module.loadAdapter(ModuleDelegate.class, null);
+		if(delegate != null) {
+			IProject[] refs = project.getReferencedProjects();
+			for(int i = 0; i < refs.length; i++) {
+				boolean found = false;
+				IModule[] children = delegate.getChildModules();
+				for(int j = 0; j < children.length; j++) {
+					if(children[j].getProject().equals(refs[i])) {
+						found = true;
+						break;
+					}
+				}
+				if(!found) {
+					processJavaProject(refs[i], entries, true);
+				}
+			}
+		}
+		return entries;
+	}
+
+	private void delete(File dummyJarFile) throws CoreException {
+		if(dummyJarFile.delete()) {
+			Trace.trace(Trace.INFO, dummyJarFile.getAbsolutePath() + " deleted sucessfully.");
+		} else {
+			Trace.trace(Trace.SEVERE, "Failed to delete " + dummyJarFile.getAbsolutePath(), null);
+			throw new CoreException(new Status(IStatus.ERROR,Activator.PLUGIN_ID,"Failed to delete " + dummyJarFile.getAbsolutePath(),null));
+		}
+	}
+
+	private void processJavaProject(IProject project, HashSet entries, boolean includeOutputLocations) throws JavaModelException {
+		IJavaProject jp = JavaCore.create(project);
+		IClasspathEntry[] cp = jp.getRawClasspath();
+		for (int i = 0; i < cp.length; i++) {
+			IClasspathEntry entry = cp[i];
+			int kind = entry.getEntryKind();
+			String path = null;
+			if(kind == IClasspathEntry.CPE_CONTAINER) {
+				if("org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER".equals(entry.getPath().toString())) {
+					IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), jp);
+					IClasspathEntry[] containerEntries = container.getClasspathEntries();
+					for(int j = 0; j  < containerEntries.length; j++) {
+						addEntry(entries, resolveVarOrLibEntry(containerEntries[j]));
+					}
+				}
+			} else if (kind == IClasspathEntry.CPE_PROJECT) {
+				IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().segment(0));
+				IJavaProject ref = JavaCore.create(p);
+				path = p.getLocation().removeLastSegments(1).append(ref.getOutputLocation()).addTrailingSeparator().toOSString();
+			} else if (kind == IClasspathEntry.CPE_SOURCE) {
+				// this if not combined with parent statement to filter out
+				// CPE_SOURCE entries from following else statement
+				// if no outputlocation, output path will get picked up by
+				// default output path
+				if(includeOutputLocations && entry.getOutputLocation() != null) {
+                    path = project.getLocation().append(entry.getOutputLocation().removeFirstSegments(1)).addTrailingSeparator().toOSString();
+				}
+			} else {
+				path = resolveVarOrLibEntry(entry);
+			}
+			addEntry(entries, path);
+		}
+		
+		if(includeOutputLocations) {
+            String path = project.getLocation().append(jp.getOutputLocation().removeFirstSegments(1)).addTrailingSeparator().toOSString();
+			addEntry(entries, path);
+		}
+	}
+
+	private String resolveVarOrLibEntry(IClasspathEntry entry) {
+		IClasspathEntry resolved = JavaCore.getResolvedClasspathEntry(entry);
+		IPath resolvedPath = resolved.getPath().makeAbsolute();
+		IProject candiate = ResourcesPlugin.getWorkspace().getRoot().getProject(resolvedPath.segment(0));
+		// check if resolvedPath is a project resource
+		if(candiate.exists(resolvedPath.removeFirstSegments(1))) {
+			return candiate.getLocation().append(resolvedPath.removeFirstSegments(1)).toOSString();
+		} else {
+			return resolvedPath.toOSString();
+		}
+	}
+
+	private void addEntry(HashSet entries, String path) {
+		if(path != null) {
+			File f = new File(path);
+			try {
+				String url = f.toURL().toExternalForm();
+				if (!entries.contains(url)) {
+					Trace.trace(Trace.INFO, "Adding " + url);
+					monitor.subTask("Linking " + url + " to shared lib.");
+					entries.add(url);
+				}
+			} catch (MalformedURLException e1) {
+				Trace.trace(Trace.INFO, "Failed to add " + path);
+				e1.printStackTrace();
+			}
+		}
+	}
+
+	/**
+	 * @param entries
+	 * @return
+	 */
+	private String getCPEntriesAsString(Set entries) {
+		StringBuffer buffer = new StringBuffer();
+		Iterator i = entries.iterator();
+		while (i.hasNext()) {
+			String cpEntry = (String) i.next();
+			buffer.append(cpEntry);
+			if (i.hasNext()) {
+				buffer.append(" ");
+			}
+		}
+		return buffer.toString();
+	}
+
+	/**
+	 * @param jarPath
+	 * @param entries
+	 * @return
+	 * @throws Exception
+	 */
+	private boolean regenerate(File jarFile, Set entries) throws Exception {
+		if (jarFile.exists()) {
+			if (entries.isEmpty()) {
+				// go ahead and return if zero entires, dummy jar will be
+				// deleted
+				return true;
+			} else {
+				JarFile jar = new JarFile(jarFile);
+				Manifest manifest = jar.getManifest();
+				Attributes attributes = manifest.getMainAttributes();
+				String value = attributes.getValue(Attributes.Name.CLASS_PATH);
+				jar.close();
+
+				Set currentEntries = new HashSet();
+				if (value != null) {
+					StringTokenizer tokenizer = new StringTokenizer(value);
+					while (tokenizer.hasMoreTokens()) {
+						currentEntries.add(tokenizer.nextToken());
+					}
+				}
+				// regen dummy jar if old and new entries don't match
+				return !entries.equals(currentEntries);
+			}
+		}
+
+		return !entries.isEmpty();
+	}
+	
+	private void stopSharedLib() throws Exception {
+		DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(server);
+		TargetModuleID id = getSharedLibTargetModuleID();
+		TargetModuleID[] ids = new TargetModuleID[]{id};
+		ProgressObject po = dm.stop(ids);
+		waitForProgress(po);
+		if(po.getDeploymentStatus().isFailed()) {
+			throw new Exception(po.getDeploymentStatus().getMessage());
+		} 
+	}
+	
+	private void startSharedLib() throws Exception {
+		DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(server);
+		TargetModuleID id = getSharedLibTargetModuleID();
+		ProgressObject po = dm.start(new TargetModuleID[]{id});
+		waitForProgress(po);
+		if(po.getDeploymentStatus().isFailed()) {
+			throw new Exception(po.getDeploymentStatus().getMessage());
+		} 
+	}
+	
+	private TargetModuleID getSharedLibTargetModuleID() throws Exception {
+		if(sharedLibTarget == null) {
+			DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(server);
+			TargetModuleID[] ids = dm.getAvailableModules(null, dm.getTargets());
+			for(int i = 0; i < ids.length; i++) {
+				if(ids[i].getModuleID().indexOf("sharedlib") > 0) {
+					sharedLibTarget = ids[i];
+					break;
+				}
+			}	
+		}
+		
+		if(sharedLibTarget == null) {
+			throw new Exception("Could not determine SharedLib TargetModuleID.");
+		}
+		
+		return sharedLibTarget;
+	}
+
+	private void waitForProgress(ProgressObject po) {
+		while (po.getDeploymentStatus().isRunning()) {
+			try {
+				Thread.sleep(100);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		DeploymentStatus status = po.getDeploymentStatus();
+		String command = status.getCommand().toString();
+		String state = status.getState().toString();
+		Trace.trace(Trace.INFO, "SharedLib " + " " + command + " " + state);
+	}
+}

Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryDataModelProvider.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryDataModelProvider.java?rev=952535&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryDataModelProvider.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/SharedLibEntryDataModelProvider.java Tue Jun  8 04:40:16 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v21.core.operations;
+
+import java.util.Set;
+
+import org.apache.geronimo.st.core.operations.ISharedLibEntryCreationDataModelProperties;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+
+/**
+ * @version $Rev: 471551 $ $Date: 2006-11-06 06:47:11 +0800 (Mon, 06 Nov 2006) $
+ */
+public class SharedLibEntryDataModelProvider extends AbstractDataModelProvider implements ISharedLibEntryCreationDataModelProperties {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider#getPropertyNames()
+	 */
+	public Set getPropertyNames() {
+		Set names = super.getPropertyNames();
+		names.add(MODULES);
+		names.add(SERVER);
+		return names;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider#getDefaultOperation()
+	 */
+	public IDataModelOperation getDefaultOperation() {
+		return new SharedLibEntryCreationOperation(model);
+	}
+}

Modified: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/V21DeploymentPlanCreationOperation.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/V21DeploymentPlanCreationOperation.java?rev=952535&r1=952534&r2=952535&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/V21DeploymentPlanCreationOperation.java (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/V21DeploymentPlanCreationOperation.java Tue Jun  8 04:40:16 2010
@@ -29,8 +29,8 @@ import org.apache.geronimo.jee.deploymen
 import org.apache.geronimo.jee.openejb.OpenejbJar;
 import org.apache.geronimo.jee.web.WebApp;
 import org.apache.geronimo.st.core.jaxb.JAXBUtils;
-import org.apache.geronimo.st.core.operations.DeploymentPlanCreationOperation;
-import org.apache.geronimo.st.v21.core.DeploymentPlanInstallConfig;
+import org.apache.geronimo.st.v21.core.operations.DeploymentPlanCreationOperation;
+import org.apache.geronimo.st.core.DeploymentPlanInstallConfig;
 import org.apache.geronimo.st.v21.core.internal.Trace;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.wst.common.frameworks.datamodel.IDataModel;

Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/test/java/org/apache/geronimo/st/v21/core/internal/DependencyHelperTest.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/test/java/org/apache/geronimo/st/v21/core/internal/DependencyHelperTest.java?rev=952535&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/test/java/org/apache/geronimo/st/v21/core/internal/DependencyHelperTest.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v21.core/src/test/java/org/apache/geronimo/st/v21/core/internal/DependencyHelperTest.java Tue Jun  8 04:40:16 2010
@@ -0,0 +1,826 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.st.v21.core.internal;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.st.v21.core.internal.DependencyHelper;
+import org.xml.sax.InputSource;
+
+/**
+ * <b>DependencyHelperTest</b> is used to test various inter-dependencies between various 
+ * Geronimo-specific deployment plans (represented by JAXBElements)<p> 
+ * 
+ * @version $Rev: 685643 $ $Date: 2008-08-14 03:24:11 +0800 (Thu, 14 Aug 2008) $ 
+ */
+public class DependencyHelperTest extends TestCase {
+
+    private DependencyHelper dh = new DependencyHelper();
+    private Object jaxbElement1;
+    private Object jaxbElement2;
+    private Object jaxbElement3;
+    private Object jaxbElement4;
+    private Object jaxbElement5;
+    private Object jaxbElement6;
+    private Object jaxbElement7;
+    private Object jaxbElement8;
+    private Object jaxbElement9;
+    private Object jaxbElement10;
+    private Object jaxbElement11;
+    private Object jaxbElement12;
+    private Object jaxbElement13;
+    private List<JAXBElement> jaxbElements = new ArrayList<JAXBElement>();
+    private List<JAXBElement> jaxbReordered = new ArrayList<JAXBElement>();
+
+    // 
+    // JAXBContext instantiation is costly - should be done only once 
+    // 
+    private static final JAXBContext jaxbContext = newJAXBContext();
+    private static JAXBContext newJAXBContext() {
+        try {
+            return JAXBContext.newInstance(
+                                          "org.apache.geronimo.jee.connector:" +
+                                          "org.apache.geronimo.jee.openejb:" +
+                                          "org.apache.geronimo.jee.web:" +
+                                          "org.apache.geronimo.jee.application:" +
+                                          "org.apache.geronimo.jee.applicationclient:" +
+                                          "org.apache.geronimo.jee.deployment:" +
+                                          "org.apache.geronimo.jee.naming:" +
+                                          "org.apache.geronimo.jee.security", DependencyHelperTest.class.getClassLoader() );
+        }
+        catch (JAXBException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    // 
+    // Set the JAXBElements to a known state 
+    // 
+    // TODO: Need to execute only once (i.e., TestSuite)
+    // 
+    public void setUp() throws Exception {
+
+        // 
+        // Create unmarshaller 
+        // 
+        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+
+        // 
+        // Read XML files 
+        // 
+        InputStream inputStream1 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-application-example-1.xml");
+        InputStream inputStream2 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-ra-example-2.xml");
+        InputStream inputStream3 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-3.xml");
+        InputStream inputStream4 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-4.xml");
+        InputStream inputStream5 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-5.xml");
+        InputStream inputStream6 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-6.xml");
+        InputStream inputStream7 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-7.xml");
+        InputStream inputStream8 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-8.xml");
+        InputStream inputStream9 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/openejb-jar-example-9.xml");
+        InputStream inputStream10 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/openejb-jar-example-10.xml");
+        InputStream inputStream11 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-ra-example-11.xml");
+        InputStream inputStream12 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-12.xml");
+        InputStream inputStream13 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-13.xml");
+        String file1 = readContent(inputStream1);
+        String file2 = readContent(inputStream2);
+        String file3 = readContent(inputStream3);
+        String file4 = readContent(inputStream4);
+        String file5 = readContent(inputStream5);
+        String file6 = readContent(inputStream6);
+        String file7 = readContent(inputStream7);
+        String file8 = readContent(inputStream8);
+        String file9 = readContent(inputStream9);
+        String file10 = readContent(inputStream10);
+        String file11 = readContent(inputStream11);
+        String file12 = readContent(inputStream12);
+        String file13 = readContent(inputStream13);
+
+        // 
+        // Unmarshall all files
+        // 
+        jaxbElement1 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file1.getBytes())));
+        jaxbElement2 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file2.getBytes())));
+        jaxbElement3 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file3.getBytes())));
+        jaxbElement4 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file4.getBytes())));
+        jaxbElement5 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file5.getBytes())));
+        jaxbElement6 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file6.getBytes())));
+        jaxbElement7 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file7.getBytes())));
+        jaxbElement8 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file8.getBytes())));
+        jaxbElement9 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file9.getBytes())));
+        jaxbElement10 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file10.getBytes())));
+        jaxbElement11 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file11.getBytes())));
+        jaxbElement12 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file12.getBytes())));
+        jaxbElement13 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file13.getBytes())));
+
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+
+    /*--------------------------------------------------------------------------------------------*\
+    |                                                                                              |
+    |  Testcase(s)                                                                                 |
+    |                                                                                              |
+    \*--------------------------------------------------------------------------------------------*/ 
+
+    public void testSingleParent() {
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car | 
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement4
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(0) );       // jaxbElement3
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement6
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(0) );       // jaxbElement5
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testMultipleParents() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 5
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );       
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 0  
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(0) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testMultipleChildrenAndParents1() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 6
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 6
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(0) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 6
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(4) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(6) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(1) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(3) );       // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testMultipleChildrenAndParents2() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    2    | null                           | org.apache.derby/derby//jar
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 7
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 7
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(0) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 7
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(6) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(7) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(1) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(3) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(4) );       // jaxbElement2
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testCircularDependency() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    2    | null                           | org.apache.derby/derby//jar
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    9    | default/openejb-jar-1/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   10    | default/openejb-jar-2/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-ra-2/1.0/car 
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   11    | default/geronimo-ra-2/1.0/car  | org.apache.derby/derby//jar 
+        //         |                                | default/openejb-jar-2/2.0/ear
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 10
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(8) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(9) );       // jaxbElement10
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement11
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 10
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(4) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(0) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(8) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(7) );       // jaxbElement11
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(1) );       // jaxbElement10
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(2) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(3) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(9) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 10
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(7) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(8) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(9) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(1) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(3) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(4) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(5) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(6) );       // jaxbElement11
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement10
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+
+    public void testCircularDependencyOnSelf() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //   12    | default/geronimo-web-7/1.0/car | default/geronimo-web-7/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement12 );                 // Element 0
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement12
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //   12    | default/geronimo-web-7/1.0/car | default/geronimo-web-7/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement12 );                 // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement12
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    2    | null                           | org.apache.derby/derby//jar
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    9    | default/openejb-jar-1/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   10    | default/openejb-jar-2/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-ra-2/1.0/car 
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   11    | default/geronimo-ra-2/1.0/car  | org.apache.derby/derby//jar 
+        //         |                                | default/openejb-jar-2/2.0/ear
+        //---------+--------------------------------+-----------------------------------------------
+        //   12    | default/geronimo-web-7/1.0/car | default/geronimo-web-7/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 10
+        jaxbElements.add( (JAXBElement)jaxbElement12 );                 // Element 11
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(8) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(9) );       // jaxbElement10
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement11
+        assertEquals( jaxbReordered.get(11),jaxbElements.get(11) );     // jaxbElement12
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    2    | null                           | org.apache.derby/derby//jar
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-7/1.0/car | default/geronimo-web-7/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    9    | default/openejb-jar-1/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   10    | default/openejb-jar-2/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-ra-2/1.0/car 
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   11    | default/geronimo-ra-2/1.0/car  | org.apache.derby/derby//jar 
+        //         |                                | default/openejb-jar-2/2.0/ear
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement12 );                 // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 10
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement12
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(8) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(9) );       // jaxbElement10
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement11
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+                        
+        //---------+--------------------------------+-----------------------------------------------
+        //  JAXB   |                                | 
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //   12    | default/geronimo-web-7/1.0/car | default/geronimo-web-7/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   13    | default/geronimo-web-8/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-7/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement12 );                 // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement13 );                 // Element 5
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );       
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement12
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement13
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement13 );                 // Element 0  
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement12 );                 // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement12
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(3) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(4) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(0) );       // jaxbElement13
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement2
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+
+    /*--------------------------------------------------------------------------------------------*\
+    |                                                                                              |
+    |  Private method(s)                                                                           |
+    |                                                                                              |
+    \*--------------------------------------------------------------------------------------------*/ 
+
+    private static String readContent(InputStream in) throws IOException {
+        StringBuffer sb = new StringBuffer();
+        in = new BufferedInputStream(in);
+        int i = in.read();
+        while (i != -1) {
+            sb.append((char) i);
+            i = in.read();
+        }
+        String content = sb.toString();
+        return content;
+    }
+}



Mime
View raw message