blob: 983aeb5227a02b7b3b1e31351ba9941326ab474d [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="keywords" content="extensionsdev-docs, framework, plugin, extension, dto">
<title>DTO | Eclipse Che Documentation</title>
<link rel="stylesheet" href="css/syntax.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" crossorigin="anonymous">
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">-->
<link rel="stylesheet" href="css/modern-business.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="css/customstyles.css">
<link rel="stylesheet" href="css/boxshadowproperties.css">
<!-- most color styles are extracted out to here -->
<link rel="stylesheet" href="css/theme-che.css">
<link rel="stylesheet" href="/css/coderay.css" media="screen" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js" crossorigin="anonymous"></script>
<script src="js/jquery.navgoco.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Anchor.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/2.0.0/anchor.min.js" crossorigin="anonymous"></script>
<script src="js/toc.js"></script>
<script src="js/customscripts.js"></script>
<link rel="shortcut icon" href="che/docs/images/favicon.ico">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml" title="che" href="http://0.0.0.0:4000/feed.xml">
<script>
$(document).ready(function() {
// Initialize navgoco with default options
$("#mysidebar").navgoco({
caretHtml: '',
accordion: true,
openClass: 'active', // open
save: false, // leave false or nav highlighting doesn't work right
cookie: {
name: 'navgoco',
expires: false,
path: '/'
},
slide: {
duration: 400,
easing: 'swing'
}
});
$("#collapseAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', false);
});
$("#expandAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', true);
});
});
</script>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
<script>
$(document).ready(function() {
$("#tg-sb-link").click(function() {
$("#tg-sb-sidebar").toggle();
$("#tg-sb-content").toggleClass('col-md-9');
$("#tg-sb-content").toggleClass('col-md-12');
$("#tg-sb-icon").toggleClass('fa-toggle-on');
$("#tg-sb-icon").toggleClass('fa-toggle-off');
});
});
</script>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container topnavlinks">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="fa fa-home fa-lg navbar-brand" href="index.html">&nbsp;<span class="projectTitle"> Eclipse Che Documentation</span></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<!-- toggle sidebar button -->
<li><a id="tg-sb-link" href="#"><i id="tg-sb-icon" class="fa fa-toggle-on"></i> Nav</a></li>
<!-- entries without drop-downs appear here -->
<li><a href="https://medium.com/eclipse-che-blog/" target="_blank">Blog</a></li>
<li><a href="https://github.com/eclipse/che" target="_blank">Source Code</a></li>
<!-- entries with drop-downs appear here -->
<!-- conditional logic to control which topnav appears for the audience defined in the configuration file.-->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Get Support<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="https://github.com/eclipse/che/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Akind%2Fbug" target="_blank">Known Bugs</a></li>
<li><a href="https://github.com/eclipse/che/issues/new" target="_blank">File an Issue</a></li>
<li><a href="https://stackoverflow.com/questions/tagged/eclipse-che" target="_blank">Che on StackOverflow</a></li>
</ul>
</li>
<!--
<li>
<a class="email" title="Submit feedback" href="#" onclick="javascript:window.location='mailto:?subject= feedback&body=I have some feedback about the DTO page: ' + window.location.href;"><i class="fa fa-envelope-o"></i> Feedback</a>
</li>
-->
<!--comment out this block if you want to hide search-->
<li>
<!--start search-->
<div id="search-demo-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>
<script src="js/jekyll-search.js" type="text/javascript"></script>
<script type="text/javascript">
SimpleJekyllSearch.init({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
dataSource: 'search.json',
searchResultTemplate: '<li><a href="{url}" title="DTO">{title}</a></li>',
noResultsText: 'No results found.',
limit: 10,
fuzzy: true,
})
</script>
<!--end search-->
</li>
</ul>
</div>
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div id="main">
<!-- Content Row -->
<div class="row">
<!-- Sidebar Column -->
<div class="col-md-3" id="tg-sb-sidebar">
<ul id="mysidebar" class="nav">
<li class="sidebarTitle"> </li>
<li>
<a href="#">Overview</a>
<ul>
<li><a href="index.html">Introduction</a></li>
<li><a href="quick-start.html">Getting Started</a></li>
<li><a href="single-multi-user.html">Single and Multi-User Flavors</a></li>
<li><a href="infra-support.html">Supported Infrastructures</a></li>
</ul>
</li>
<li>
<a href="#">Che on Docker</a>
<ul>
<li><a href="docker-single-user.html">Docker - Single User</a></li>
<li><a href="docker-multi-user.html">Docker - Multi User</a></li>
<li><a href="docker-config.html">Docker - Configuration</a></li>
<li><a href="docker-cli.html">Docker - CLI Reference</a></li>
</ul>
</li>
<li>
<a href="#">Che on Kubernetes</a>
<ul>
<li><a href="kubernetes-single-user.html">Kubernetes - Single User</a></li>
<li><a href="kubernetes-multi-user.html">Kubernetes - Multi User</a></li>
<li><a href="kubernetes-config.html">Kubernetes - Configuration</a></li>
<li><a href="kubernetes-admin-guide.html">Kubernetes - Admin Guide</a></li>
</ul>
</li>
<li>
<a href="#">Che on OpenShift</a>
<ul>
<li><a href="openshift-single-user.html">OpenShift - Single User</a></li>
<li><a href="openshift-multi-user.html">OpenShift - Multi User</a></li>
<li><a href="openshift-config.html">OpenShift - Configuration</a></li>
<li><a href="openshift-admin-guide.html">OpenShift - Admin Guide</a></li>
</ul>
</li>
<li>
<a href="#">User Management</a>
<ul>
<li><a href="user-management.html">Authentication and Authorization</a></li>
<li><a href="authentication.html">Security Model</a></li>
<li><a href="permissions.html">Permissions</a></li>
<li><a href="organizations.html">Organizations in UD</a></li>
<li><a href="resource-management.html">Resource Management</a></li>
</ul>
</li>
<li>
<a href="#">User Guides</a>
<ul>
<li><a href="creating-starting-workspaces.html">Creating and starting Workspaces</a></li>
<li><a href="ide-projects.html">Projects</a></li>
<li><a href="editor-code-assistance.html">Editor and Code-Assistance</a></li>
<li><a href="dependency-management.html">Dependency Management</a></li>
<li><a href="commands-ide-macro.html">Commands and IDE Macros</a></li>
<li><a href="version-control.html">Version Control</a></li>
<li><a href="debug.html">Debug</a></li>
</ul>
</li>
<li>
<a href="#">Workspace Administration</a>
<ul>
<li><a href="what-are-workspaces.html">Workspace Overview</a></li>
<li><a href="stacks.html">Workspace - Stacks</a></li>
<li><a href="recipes.html">Workspace - Recipes</a></li>
<li><a href="servers.html">Workspace - Servers</a></li>
<li><a href="installers.html">Workspace - Installers</a></li>
<li><a href="volumes.html">Workspace - Volumes Mount</a></li>
<li><a href="env-variables.html">Workspace - Environment Variables</a></li>
<li><a href="projects.html">Workspace - Projects</a></li>
<li><a href="workspaces-troubleshooting.html">Workspace - Troubleshooting</a></li>
<li><a href="workspace-data-model.html">Workspace Data Model</a></li>
</ul>
</li>
<li>
<a href="#">Portable Workspaces</a>
<ul>
<li><a href="chedir-getting-started.html">Chedir - Getting Started</a></li>
<li><a href="why-chedir.html">Chedir - Why Chedir?</a></li>
<li><a href="chedir-installation.html">Chedir - Installation</a></li>
<li><a href="chedir-project-setup.html">Chedir - Project Setup</a></li>
<li><a href="chedir-up-and-down.html">Chedir - Up and Down</a></li>
<li><a href="chefile.html">Chedir - Chefile</a></li>
<li><a href="chedir-ssh.html">Chedir - SSH</a></li>
<li><a href="factories-getting-started.html">Factory - Getting Started</a></li>
<li><a href="creating-factories.html">Factory - Creating</a></li>
<li><a href="factories_json_reference.html">Factory - JSON Reference</a></li>
</ul>
</li>
<li>
<a href="#">Developer Guides</a>
<ul>
<li><a href="framework-overview.html">Overview</a></li>
<li><a href="rest-api.html">SDK - REST API</a></li>
<li><a href="che-in-che-quickstart.html">SDK - Your First Plugin</a></li>
<li><a href="build-reqs.html">SDK - Building Che</a></li>
<li><a href="assemblies.html">SDK - Assemblies</a></li>
<li><a href="logging.html">SDK - Logging</a></li>
<li><a href="ide-extensions-gwt.html">SDK - GWT IDE Extensions</a></li>
<li><a href="server-side-extensions.html">SDK - Server Side Extensions</a></li>
<li><a href="custom-installers.html">SDK - Installers</a></li>
<li><a href="project-types.html">SDK - Project Types</a></li>
<li><a href="language-servers.html">SDK - Language Support</a></li>
<li><a href="parts.html">IDE UI&#58 Parts</a></li>
<li><a href="actions.html">IDE UI&#58 Actions</a></li>
</ul>
</li>
<li>
<a href="#">Dev Essentials</a>
<ul>
<li><a href="guice.html">Dependency Injection</a></li>
<li class="active"><a href="dto.html">Transport&#58 DTO</a></li>
<li><a href="json-rpc.html">Communication&#58 JSON-RPC</a></li>
<li><a href="handling-projects-in-plugins.html">Handling Projects in Plugins</a></li>
<li><a href="dao.html">Persistence, DAO</a></li>
<li><a href="properties.html">Properties</a></li>
</ul>
</li>
<li>
<a href="#">Infrastructure and SPI</a>
<ul>
<li><a href="spi_overview.html">Overview</a></li>
<li><a href="spi-implementation.html">Implementation Notes</a></li>
</ul>
</li>
<!-- if you aren't using the accordion, uncomment this block:
<p class="external">
<a href="#" id="collapseAll">Collapse All</a> | <a href="#" id="expandAll">Expand All</a>
</p>
-->
</ul>
<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<script>$("li.active").parents('li').toggleClass("active");</script>
</div>
<!-- Content Column -->
<div class="col-md-9" id="tg-sb-content">
<div class="post-header">
<h1 class="post-title-main">DTO</h1>
</div>
<div class="post-content">
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
<script>
$( document ).ready(function() {
// Handler for .ready() called.
$('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2' });
/* this offset helps account for the space taken up by the floating toolbar. */
$('#toc').on('click', 'a', function() {
var target = $(this.getAttribute('href'))
, scroll_target = target.offset().top
$(window).scrollTop(scroll_target - 10);
return false
})
});
</script>
<div id="toc"></div>
<!--
-->
<div class="paragraph">
<p>A data transfer object (DTO) is an object to exchange data with the client and server. DTOs are responsible for serializing (and deserializing) themselves into JSON. You can prepare custom DTOs for your extensions and plugins. You define a DTO interface and then our DTO utilities will generate implementations that can be included in your extension.</p>
</div>
<div class="sect1">
<h2 id="interfaces">Interfaces</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Every DTO requires interfaces that must contain get-methods. Mark these interfaces with the <code>org.eclipse.che.dto.shared.DTO</code> annotation. Possible names for getter-methods are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>get...
is...</pre>
</div>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">package</span> <span class="namespace">com.codenvy.test.dto</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.che.dto.shared.DTO</span>;
<span class="annotation">@DTO</span>
<span class="directive">public</span> <span class="type">interface</span> <span class="class">Item</span> {
<span class="predefined-type">String</span> getStatus();
<span class="type">void</span> setStatus(<span class="predefined-type">String</span> status);
<span class="type">boolean</span> isHidden();
<span class="type">void</span> setHidden(<span class="type">boolean</span> hidden);
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="pom">POM</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Update the <code>&lt;plugins&gt;</code> section of a <code>pom.xml</code> to include the DTO.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><code>maven-compiler-plugin</code> - helps to run compilation of project in two steps.</p>
</li>
<li>
<p><code>che-core-api-dto-maven-plugin</code> - generates DTO implementations.</p>
</li>
<li>
<p><code>build-helper-maven-plugin</code> - adds generated files to project’s sources.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p><code>che-core-api-dto-maven-plugin</code> has the following configuration parameters (all required):</p>
</div>
<div class="paragraph">
<p><code>dtoPackages</code>: names of packages which contains DTO interfaces.</p>
</div>
<div class="paragraph">
<p><code>outputDirectory</code>: name of directory to store generated files. Usually just set one property, e.g. <code>dto-generator-out-directory</code> and reuse it in configurations of plugins.</p>
</div>
<div class="paragraph">
<p><code>genClassName</code>: sets the name of an enclosing class where generated classes are placed.</p>
</div>
<div class="paragraph">
<p><code>impl</code>: either <code>server</code> or <code>client</code> to define which kind of DTO to generate.</p>
</div>
<div class="paragraph">
<p><code>dependencies</code> - each maven plugin has its own classloader. Plugin cannot see dependencies or build output of current project. So it’s necessary to add current project as dependency for <code>che-core-api-dto-maven-plugin</code>. If DTOs from current project use DTOs from another project, then need add dependency to that project too.</p>
</div>
<div class="paragraph">
<p>The following <code>pom.xml</code> snippet demonstrates how you can generate server-side DTOs:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>...
&lt;properties&gt;
&lt;dto-generator-out-directory&gt;${project.build.directory}/generated-sources/dto/&lt;/dto-generator-out-directory&gt;
&lt;/properties&gt;
...
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;pre-compile&lt;/id&gt;
&lt;phase&gt;generate-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;compile&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.eclipse.che.core&lt;/groupId&gt;
&lt;artifactId&gt;che-core-api-dto-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${che.core.version}&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;phase&gt;process-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;generate&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
&lt;dtoPackages&gt;
&lt;package&gt;com.codenvy.test.dto&lt;/package&gt;
&lt;/dtoPackages&gt;
&lt;outputDirectory&gt;${dto-generator-out-directory}&lt;/outputDirectory&gt;
&lt;genClassName&gt;com.codenvy.test.server.dto.DtoServerImpls&lt;/genClassName&gt;
&lt;impl&gt;server&lt;/impl&gt;
&lt;/configuration&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
&lt;artifactId&gt;${project.artifactId}&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;!--
Other dependencies if DTOs from current project need them.
--&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
&lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;add-resource&lt;/id&gt;
&lt;phase&gt;process-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;add-resource&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;resources&gt;
&lt;resource&gt;
&lt;directory&gt;${dto-generator-out-directory}/META-INF&lt;/directory&gt;
&lt;targetPath&gt;META-INF&lt;/targetPath&gt;
&lt;/resource&gt;
&lt;/resources&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;add-source&lt;/id&gt;
&lt;phase&gt;process-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;add-source&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;sources&gt;
&lt;source&gt;${dto-generator-out-directory}&lt;/source&gt;
&lt;/sources&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
...</pre>
</div>
</div>
<div class="paragraph">
<p>The following <code>pom.xml</code> snippet demonstrates how you can generate both types of DTOs (client and server):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>...
&lt;properties&gt;
&lt;dto-generator-out-directory&gt;${project.build.directory}/generated-sources/dto/&lt;/dtogenerator-out-directory&gt;
&lt;/properties&gt;
...
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;pre-compile&lt;/id&gt;
&lt;phase&gt;generate-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;compile&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.eclipse.che.core&lt;/groupId&gt;
&lt;artifactId&gt;che-core-api-dto-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${che.core.version}&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;phase&gt;process-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;generate&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;dtoPackages&gt;
&lt;package&gt;com.codenvy.test.dto&lt;/package&gt;
&lt;/dtoPackages&gt;
&lt;outputDirectory&gt;${dto-generator-out-directory}&lt;/outputDirectory&gt;
&lt;genClassName&gt;com.codenvy.test.client.dto.DtoClientImpls&lt;/genClassName&gt;
&lt;impl&gt;client&lt;/impl&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;phase&gt;process-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;generate&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;dtoPackages&gt;
&lt;package&gt;com.codenvy.test.dto&lt;/package&gt;
&lt;/dtoPackages&gt;
&lt;outputDirectory&gt;${dto-generator-out-directory}&lt;/outputDirectory&gt;
&lt;genClassName&gt;com.codenvy.test.server.dto.DtoServerImpls&lt;/genClassName&gt;
&lt;impl&gt;server&lt;/impl&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
&lt;artifactId&gt;${project.artifactId}&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;!--
Other dependencies if DTOs from current project need them.
--&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
&lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;add-resource&lt;/id&gt;
&lt;phase&gt;process-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;add-resource&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;resources&gt;
&lt;resource&gt;
&lt;directory&gt;${dto-generator-out-directory}/META-INF&lt;/directory&gt;
&lt;targetPath&gt;META-INF&lt;/targetPath&gt;
&lt;/resource&gt;
&lt;/resources&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;add-source&lt;/id&gt;
&lt;phase&gt;process-sources&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;add-source&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;sources&gt;
&lt;source&gt;${dto-generator-out-directory}&lt;/source&gt;
&lt;/sources&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;resources&gt;
...
&lt;resource&gt;
&lt;directory&gt;${generated.sources.directory}&lt;/directory&gt;
&lt;/resource&gt;
&lt;/resources&gt;
&lt;/build&gt;
...</pre>
</div>
</div>
<div class="paragraph">
<p>Make sure that the directory with generated client-side DTOs is included in classpath resources.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="generate">Generate</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In order to generate DTOs, you build your project with maven:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>mvn clean install</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="use-server-side">Use: Server-Side</h2>
<div class="sectionbody">
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// server-side DTO</span>
<span class="keyword">import</span> <span class="include">org.eclipse.che.dto.server.DtoFactory</span>;
...
<span class="comment">// create instance and set fields</span>
MyJob job = DtoFactory.getInstance().createDto(MyJob.class);
job.setStatus(<span class="string"><span class="delimiter">&quot;</span><span class="content">success</span><span class="delimiter">&quot;</span></span>);
job.setExitCode(<span class="integer">0</span>);
<span class="comment">// serialize to JSON</span>
<span class="predefined-type">String</span> json = DtoFactory.getInstance().toJson(job);
<span class="comment">// deserialize from JSON</span>
MyJob job2 = DtoFactory.getInstance().createDtoFromJson(json, MyJob.class);</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also use the static method <code>DtoFactory.newDto(MyJob.class)</code> that is a shortcut for <code>DtoFactory.getInstance().createDto(MyJob.class)</code>. See: <a href="https://github.com/eclipse/che/blob/master/core/che-core-api-dto/src/main/java/org/eclipse/che/dto/server/DtoFactory.java">DtoFactory</a> for server side.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="use-client-side">Use: Client-Side</h2>
<div class="sectionbody">
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// client-side DTO</span>
<span class="keyword">import</span> <span class="include">org.eclipse.che.ide.dto.DtoFactory</span>;
<span class="annotation">@Singleton</span>
<span class="directive">public</span> <span class="type">class</span> <span class="class">MyPresenter</span> {
<span class="annotation">@Inject</span>
<span class="directive">public</span> MyPresenter(DtoFactory dtoFactory) {
<span class="comment">// create instance and set fields</span>
MyJob job = dtoFactory.createDto(MyJob.class);
job.setStatus(<span class="string"><span class="delimiter">&quot;</span><span class="content">success</span><span class="delimiter">&quot;</span></span>);
job.setExitCode(<span class="integer">0</span>);
<span class="comment">// serialize to JSON</span>
<span class="predefined-type">String</span> json = dtoFactory.toJson(job);
<span class="comment">// deserialize from JSON</span>
MyJob job2 = dtoFactory.createDtoFromJson(json, MyJob.class);
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>See: client side <a href="https://github.com/eclipse/che/blob/master/ide/commons-gwt/src/main/java/org/eclipse/che/ide/dto/DtoFactory.java">DtoFactory</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="method-chaining">Method Chaining</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In addition to the standard getter and setter methods, our generator also adds a method <code>withXXX(T value)</code>. This is seimilar to a setter method, but also returns <code>this</code>. You can use this to do chaining. Instead of:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">MyJob job = DtoFactory.getInstance().createDto(MyJob.class);
job.setStatus(<span class="string"><span class="delimiter">&quot;</span><span class="content">success</span><span class="delimiter">&quot;</span></span>);
job.setExitCode(<span class="integer">0</span>);</code></pre>
</div>
</div>
<div class="paragraph">
<p>use:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">MyJob job =
DtoFactory.getInstance().createDto(MyJob.class).withStatus(<span class="string"><span class="delimiter">&quot;</span><span class="content">success</span><span class="delimiter">&quot;</span></span>).withExitCode(<span class="integer">0</span>);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Generator always add such methods in generated implementation for your DTO interfaces, but you still should add them to you interfaces so that they are externally accessible:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">package</span> <span class="namespace">com.codenvy.test.dto</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.che.dto.shared.DTO</span>;
<span class="annotation">@DTO</span>
<span class="directive">public</span> <span class="type">interface</span> <span class="class">MyJob</span> {
<span class="predefined-type">String</span> getStatus();
<span class="type">void</span> setStatus(<span class="predefined-type">String</span> status);
<span class="type">int</span> getExitCode();
<span class="type">void</span> setExitCode(<span class="type">int</span> code);
<span class="predefined-type">String</span> getError();
<span class="type">void</span> setError(<span class="predefined-type">String</span> error);
<span class="comment">// for chaining</span>
MyJob withStatus(<span class="predefined-type">String</span> status);
MyJob withExitCode(<span class="type">int</span> code);
MyJob withError(<span class="predefined-type">String</span> error);
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="delegate-dto-methods">Delegate DTO Methods</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In some case we may need more then just getters and setters in DTO, but there is no common mechanism to generate such implementation for DTO interface. In this case <code>org.eclipse.che.dto.shared.DelegateTo</code> annotation may help. DTO interface bellow contains getters, setters and with methods and one more complex method for getting full name of user.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="annotation">@DTO</span>
<span class="directive">public</span> <span class="type">interface</span> <span class="class">User</span> {
<span class="predefined-type">String</span> getFirstName();
<span class="type">void</span> setFirstName(<span class="predefined-type">String</span> firstName);
User withFirstName(<span class="predefined-type">String</span> firstName);
<span class="predefined-type">String</span> getLastName();
<span class="type">void</span> setLastName(<span class="predefined-type">String</span> lastName);
User withLastName(<span class="predefined-type">String</span> lastName);
<span class="annotation">@DelegateTo</span>(client = <span class="annotation">@DelegateRule</span>(type = <span class="predefined-type">Util</span>.class, method = <span class="string"><span class="delimiter">&quot;</span><span class="content">fullName</span><span class="delimiter">&quot;</span></span>),
server = <span class="annotation">@DelegateRule</span>(type = <span class="predefined-type">Util</span>.class, method = <span class="string"><span class="delimiter">&quot;</span><span class="content">fullName</span><span class="delimiter">&quot;</span></span>))
<span class="predefined-type">String</span> getFullName();
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For method <code>getFullName</code> add annotation <code>DelegateTo</code>. Annotations may contains different delegate rules for client and server code.</p>
</div>
<div class="paragraph">
<p><code>DelegateTo</code> annotation:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>client</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Rules for client code generator</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>server</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Rules for server code generator</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><code>DelegateRule</code> annotation</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>type</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Class that contains method to delegate method call</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>method</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Name of method</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">Util</span> {
<span class="directive">public</span> <span class="directive">static</span> <span class="predefined-type">String</span> fullName(User user) {
<span class="keyword">return</span> user.getFirstName() + <span class="string"><span class="delimiter">&quot;</span><span class="content"> </span><span class="delimiter">&quot;</span></span> + user.getLastName();
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Fragment of generated code for method <code>getFullName()</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="predefined-type">String</span> getFullName() {
<span class="keyword">return</span> <span class="predefined-type">Util</span>.fullName(<span class="local-variable">this</span>);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Requirements for methods to delegate DTO methods calls:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Method must be public and static.</p>
</li>
<li>
<p>Method must accept DTO interface as first parameter, if DTO method contains other parameters then the delegate method must accept the whole set of DTO method parameters starting from the second position.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="annotation">@DelegateTo</span>(client = <span class="annotation">@DelegateRule</span>(type = <span class="predefined-type">Util</span>.class, method = <span class="string"><span class="delimiter">&quot;</span><span class="content">fullName</span><span class="delimiter">&quot;</span></span>),
server = <span class="annotation">@DelegateRule</span>(type = <span class="predefined-type">Util</span>.class, method = <span class="string"><span class="delimiter">&quot;</span><span class="content">fullName</span><span class="delimiter">&quot;</span></span>))
<span class="predefined-type">String</span> getFullNameWithPrefix(<span class="predefined-type">String</span> prefix);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Delegate method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="predefined-type">String</span> fullName(User user, <span class="predefined-type">String</span> prefix) {
<span class="keyword">return</span> prefix + <span class="string"><span class="delimiter">&quot;</span><span class="content"> </span><span class="delimiter">&quot;</span></span> + user.getFirstName() + <span class="string"><span class="delimiter">&quot;</span><span class="content"> </span><span class="delimiter">&quot;</span></span> + user.getLastName();
}</code></pre>
</div>
</div>
</div>
</div>
<div class="tags">
<b>Tags: </b>
<a href="tag_extensions.html" class="btn btn-default navbar-btn cursorNorm" role="button">extensions</a>
<a href="tag_dev-docs.html" class="btn btn-default navbar-btn cursorNorm" role="button">dev-docs</a>
</div>
<!--
-->
</div>
<hr class="shaded"/>
<footer>
<div class="row">
<div class="col-lg-12 footer">
Eclipse Che - Documentation <br/>
Site last generated: Sep 13, 2018 <br/>
<hr>
<a href="http://www.eclipse.org" target="_blank">Eclipse Foundation</a><br/>
<a href="http://www.eclipse.org/legal/privacy.php" target="_blank">Privacy Policy</a><br/>
<a href="http://www.eclipse.org/legal/termsofuse.php" target="_blank">Terms of Use</a><br/>
<a href="https://www.eclipse.org/legal/epl-2.0/" target="_blank">Eclipse Public License</a><br/>
<a href="http://www.eclipse.org/legal" target="_blank">Legal Resources</a><br/>
</div>
</div>
</footer>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
<!-- /#main -->
</div>
</body>
</html>