diff options
author | Caspar De Groot | 2011-04-07 04:06:55 +0000 |
---|---|---|
committer | Caspar De Groot | 2011-04-07 04:06:55 +0000 |
commit | d41475ec4a284047a3d3f160a8084b5c0934f8bc (patch) | |
tree | 3363420a4bbda4bf80e29322dec00c8ae9cdf69e /plugins/org.eclipse.emf.cdo.examples/src | |
parent | 1d968cce2f0b3d23e61449b244b7e1af36abf8f6 (diff) | |
download | cdo-d41475ec4a284047a3d3f160a8084b5c0934f8bc.tar.gz cdo-d41475ec4a284047a3d3f160a8084b5c0934f8bc.tar.xz cdo-d41475ec4a284047a3d3f160a8084b5c0934f8bc.zip |
[Bug 340108] SSL transport implementation for Net4J
https://bugs.eclipse.org/bugs/show_bug.cgi?id=340108
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.examples/src')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneContainerExampleSSL.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneContainerExampleSSL.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneContainerExampleSSL.java new file mode 100644 index 0000000000..f85e3eec15 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneContainerExampleSSL.java @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others. + * 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.examples; + +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.examples.company.CompanyFactory; +import org.eclipse.emf.cdo.examples.company.CompanyPackage; +import org.eclipse.emf.cdo.net4j.CDONet4jUtil; +import org.eclipse.emf.cdo.net4j.CDOSessionConfiguration; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CommitException; + +import org.eclipse.net4j.Net4jUtil; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.tcp.ssl.SSLUtil; +import org.eclipse.net4j.util.container.ContainerUtil; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.log.PrintLogHandler; +import org.eclipse.net4j.util.om.trace.PrintTraceHandler; + +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EObject; + +/** + * @author Eike Stepper + * @since 4.0 + */ +public class StandaloneContainerExampleSSL +{ + public static void main(String[] args) throws CommitException + { + // Enable logging and tracing + OMPlatform.INSTANCE.setDebugging(true); + OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE); + OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE); + + // Prepare container + IManagedContainer container = ContainerUtil.createContainer(); + Net4jUtil.prepareContainer(container); // Register Net4j factories + SSLUtil.prepareContainer(container); + CDONet4jUtil.prepareContainer(container); // Register CDO factories + container.activate(); + + // Create connector + IConnector connector = SSLUtil.getConnector(container, "localhost:2036"); + + // Create configuration + CDOSessionConfiguration configuration = CDONet4jUtil.createSessionConfiguration(); + configuration.setConnector(connector); + configuration.setRepositoryName("repo1"); //$NON-NLS-1$ + + // Open session + CDOSession session = configuration.openSession(); + session.options().setGeneratedPackageEmulationEnabled(true); + + session.getPackageRegistry().putEPackage(CompanyPackage.eINSTANCE); + + // Open transaction + CDOTransaction transaction = session.openTransaction(); + + // Read whatetever is there + TreeIterator<EObject> iter = transaction.getRootResource().getAllContents(); + while (iter.hasNext()) + { + System.out.println("---> It's a " + iter.next().eClass().getName()); + } + + // Get or create resource + CDOResource resource = transaction.getOrCreateResource("/path/to/my/resource"); //$NON-NLS-1$ + + // Work with the resource and commit the transaction + EObject object = CompanyFactory.eINSTANCE.createCompany(); + resource.getContents().add(object); + transaction.commit(); + + // Cleanup + session.close(); + connector.close(); + container.deactivate(); + } +} |