Commit 6f79671c authored by Romain Bioteau's avatar Romain Bioteau
Browse files

generic builders

parent 20cc057b
......@@ -28,7 +28,8 @@ import org.bonitasoft.studio.model.process.ProcessFactory;
*/
public class ActivityBuilder<T extends Activity, B extends ActivityBuilder<T, B>> extends FlowElementBuilder<T, B> {
public static ActivityBuilder<?, ?> create() {
@SuppressWarnings("rawtypes")
public static ActivityBuilder create() {
return new ActivityBuilder();
}
......@@ -121,6 +122,7 @@ public class ActivityBuilder<T extends Activity, B extends ActivityBuilder<T, B>
return getThis();
}
@SuppressWarnings("unchecked")
@Override
protected T newInstance() {
return (T) ProcessFactory.eINSTANCE.createActivity();
......
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.model.process.builders;
import org.bonitasoft.studio.model.process.Actor;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class ActorBuilder extends ElementBuilder<Actor, ActorBuilder> {
public static ActorBuilder create() {
return new ActorBuilder();
}
public ActorBuilder initiator() {
getBuiltInstance().setInitiator(true);
return getThis();
}
public ActorBuilder notInitiator() {
getBuiltInstance().setInitiator(false);
return getThis();
}
@Override
protected Actor newInstance() {
return ProcessFactory.eINSTANCE.createActor();
}
}
......@@ -26,7 +26,8 @@ import org.bonitasoft.studio.model.process.ProcessFactory;
*/
public class DataBuilder<T extends Data, B extends DataBuilder<T, B>> extends ElementBuilder<T, B> {
public static DataBuilder<?, ?> create() {
@SuppressWarnings("rawtypes")
public static DataBuilder create() {
return new DataBuilder();
}
......@@ -75,6 +76,7 @@ public class DataBuilder<T extends Data, B extends DataBuilder<T, B>> extends El
return getThis();
}
@SuppressWarnings("unchecked")
@Override
protected T newInstance() {
return (T) ProcessFactory.eINSTANCE.createData();
......
......@@ -25,19 +25,21 @@ import org.bonitasoft.studio.model.process.Element;
public abstract class ElementBuilder<T extends Element, B extends ElementBuilder<T, B>> {
protected final T builtEObject;
private final B thisBuilder;
protected ElementBuilder() {
builtEObject = newInstance();
thisBuilder = getThis();
}
public B withName(final String name) {
getBuiltInstance().setName(name);
return getThis();
return thisBuilder;
}
public B withDocumentation(final String documentation) {
getBuiltInstance().setDocumentation(documentation);
return getThis();
return thisBuilder;
}
public B havingTextAnnotationAttachment(final TextAnnotationAttachmentBuilder... textAnnotationAttachments) {
......@@ -46,13 +48,14 @@ public abstract class ElementBuilder<T extends Element, B extends ElementBuilder
getBuiltInstance().getTextAnnotationAttachment().add(annotation.build());
}
}
return getThis();
return thisBuilder;
}
public T build() {
return getBuiltInstance();
}
@SuppressWarnings("unchecked")
protected B getThis() {
return (B) this;
}
......
......@@ -25,7 +25,8 @@ import org.bonitasoft.studio.model.process.ProcessFactory;
*/
public class JavaObjectDataBuilder<T extends JavaObjectData, B extends JavaObjectDataBuilder<T, B>> extends DataBuilder<T, B> {
public static JavaObjectDataBuilder<?, ?> create() {
@SuppressWarnings("rawtypes")
public static JavaObjectDataBuilder create() {
return new JavaObjectDataBuilder();
}
......@@ -34,6 +35,7 @@ public class JavaObjectDataBuilder<T extends JavaObjectData, B extends JavaObjec
return getThis();
}
@SuppressWarnings("unchecked")
@Override
protected T newInstance() {
return (T) ProcessFactory.eINSTANCE.createJavaObjectData();
......
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.model.process.builders;
import org.bonitasoft.studio.model.parameter.builders.ParameterBuilder;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class PoolBuilder extends ElementBuilder<Pool, PoolBuilder> {
public static PoolBuilder create() {
return new PoolBuilder();
}
public PoolBuilder havingElements(final ElementBuilder<?, ?>... elements) {
if (elements != null) {
for (final ElementBuilder<?, ?> elementBuilder : elements) {
getBuiltInstance().getElements().add(elementBuilder.build());
}
}
return getThis();
}
public PoolBuilder havingActors(final ActorBuilder... actors) {
if (actors != null) {
for (final ActorBuilder actor : actors) {
getBuiltInstance().getActors().add(actor.build());
}
}
return getThis();
}
public PoolBuilder havingDocuments(final DocumentBuilder... documents) {
if (documents != null) {
for (final DocumentBuilder document : documents) {
getBuiltInstance().getDocuments().add(document.build());
}
}
return getThis();
}
public PoolBuilder havingParameters(final ParameterBuilder... parameters) {
if (parameters != null) {
for (final ParameterBuilder parameter : parameters) {
getBuiltInstance().getParameters().add(parameter.build());
}
}
return getThis();
}
public PoolBuilder havingData(final DataBuilder<?, ?>... data) {
if (data != null) {
for (final DataBuilder<?, ?> dataBuilder : data) {
getBuiltInstance().getData().add(dataBuilder.build());
}
}
return getThis();
}
@Override
protected Pool newInstance() {
return ProcessFactory.eINSTANCE.createPool();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment