Commit d72cde05 authored by Nico Mack's avatar Nico Mack

Added Bootstrapping for Content

Added support for automatic build number generation via maven
parent 9516a636
......@@ -25,6 +25,7 @@ CIRCLE_SIZE_NODE=circleSize
COLOUR_NODE=colour
COLOURSC_NODE=colourscheme
CONNECTIONS_NODE=connections
CONTENT_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.content.builder
CORNER_RADIUS_NODE=cornerRadius
CORONA_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.corona.builder
CORONA_NODE=corona
......@@ -67,6 +68,7 @@ HANDLE_NODE=handle
HANDLES_NODE=handles
HEIGHT_NODE=height
HTML_CONTENT_NODE=htmlContent
IDENTIFIER_NODE=identifier
IMAGE_BASE64_ELEMENT=imageBase64
IMAGE_ELEMENT=image
IMAGES_ELEMENT=images
......
......@@ -18,7 +18,12 @@
<comments>For commercial purposes, please contact tto@list.lu to obtain a license.</comments>
</license>
</licenses>
<scm>
<connection>scm:svn:http://none</connection>
<url>scm:svn:https://none</url>
</scm>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
......@@ -30,8 +35,40 @@
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
<timestampPropertyName>build.date</timestampPropertyName>
<revisiononscmfailure>
<format>Build: #{0} ({1,date})</format>
<items>
<item>buildNumber\d*</item>
<item>timestamp</item>
</items>
</revisiononscmfailure>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/lu/list/itis/dkd/tui/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.content.builder.ContentBuilder;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.jdom2.Element;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.2
* @version 2.3.0
*/
public class ContentBootstrapper {
/**
* Method used to determine the appropriate builder for a given object and then issue a build call.
*
* @param bootstrapContext
* @param callback
*
* @param contentNode
* The node from a larger document that contains, as children, all the necessary information
* to resolve the correct builder and build the final tether.
* @return The final tether as defined by the children of the element node.
* @throws ClassNotFoundException
* Thrown when the class of the builder for the widget or those of the nested corona
* builder(s) could not be found.
* @throws SecurityException
* Thrown when the constructor cannot be retrieved due to some security constraints.
* @throws NoSuchMethodException
* Thrown when no constructor with the given parameter type is available.
* @throws InvocationTargetException
* Thrown if the invocation of any constructor through reflection throws an exception.
* @throws IllegalArgumentException
* Thrown when the provided argument is not eligible for the builder's constructor.
* @throws IllegalAccessException
* Thrown if this Constructor object is enforcing Java language access control and the
* underlying constructor is inaccessible.
* @throws InstantiationException
* Thrown if the class that declares the underlying constructor represents an abstract
* class.
* @throws BuildException
*/
@SuppressWarnings("unchecked")
public static Content buildTetherFromElement(Element contentNode, BootstrapContext bootstrapContext, BootstrapCallback callback) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, BuildException {
Content instance = null;
Element type = contentNode.getChild(Externalization.TYPE_NODE);
Class<?> builder = Class.forName(Externalization.CONTENT_BUILDER_NAMESPACE + Externalization.NAMESPACE_SEPARATOR + type.getValue() + Externalization.BUILDER_CLASS_POSTFIX);
if ((bootstrapContext == null) || (bootstrapContext.size() == 0)) {
Constructor<ContentBuilder<?>> constructor = (Constructor<ContentBuilder<?>>) builder.getConstructor(new Class[] {Element.class});
instance = constructor.newInstance(new Object[] {contentNode}).build();
} else {
Constructor<ContentBuilder<?>> constructor = (Constructor<ContentBuilder<?>>) builder.getConstructor(new Class[] {Element.class, BootstrapContext.class, BootstrapCallback.class});
instance = constructor.newInstance(new Object[] {contentNode, bootstrapContext, callback}).build();
}
return instance;
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.content;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.content.builder.BaseContentBuilder;
import java.awt.geom.Area;
import java.util.Objects;
......@@ -36,28 +37,42 @@ import java.util.Objects;
* @version 2.3.0
*/
@NonNullByDefault
public abstract class Content { // implements Comparable<Content> {
// protected int drawPriority = 50;
public abstract class Content {
protected int stageId = 0;
protected String identifier;
protected Area clippingRegion;
// ---------------------------------------------------------------------------
/**
* Constructor initialising all necessary fields.
*
* @param identifier
* The unique identification of the {@link Content}.
*/
// ---------------------------------------------------------------------------
public Content(String identifier) {
this.identifier = identifier;
this.clippingRegion = new Area();
}
// ---------------------------------------------------------------------------
/**
* @param builder
*/
// ---------------------------------------------------------------------------
public Content(BaseContentBuilder<?> builder) {
this.stageId = builder.stageId;
this.identifier = builder.identifier;
this.clippingRegion = new Area();
}
// ---------------------------------------------------------------------------
/**
* Comparison as defined by the {@link Comparable} interface. This comparison is based on the
* integer comparison of the draw priorities, ordering lower priorities first. This will result
* in lower priority {@link Content} instances being overlapped by prioritised ones.<br>
* integer comparison of the draw priorities, ordering lower priorities first. This will result in
* lower priority {@link Content} instances being overlapped by prioritised ones.<br>
* <br>
*
* {@inheritDoc}
......@@ -81,7 +96,6 @@ public abstract class Content { // implements Comparable<Content> {
if (object instanceof Content) {
Content other = (Content) object;
// equals &= (getDrawPriority() == other.getDrawPriority());
equals &= (getStageId() == other.getStageId());
if (identifier != null) {
......@@ -100,22 +114,9 @@ public abstract class Content { // implements Comparable<Content> {
@Override
public int hashCode() {
// return Objects.hash(drawPriority, stageId, identifier);
return Objects.hash(stageId, identifier);
}
/**
* Getter method for the draw priority. The method will have to do the computation to account
* for the initialTranslation and the current position of the widget influencing the content if
* any.
*
* @return The draw priority of this content instance.
*/
// protected int getDrawPriority() {
// return drawPriority;
// }
/**
* Simple getter method for identifier.
*
......@@ -147,19 +148,6 @@ public abstract class Content { // implements Comparable<Content> {
this.stageId = id;
}
/**
* Method used to cause a recomputation of the priority of this content instance in order to
* update the order of content instances used by the tangible application.
*
* @param order
* The variable determining order depending on the implementation.
*/
// public void updateDrawPriority(int order) {
// this.drawPriority = order;
// }
/**
* Method used for initialising all fields necessary for the content to function.
*/
......
package lu.list.itis.dkd.tui.content.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.jdom2.Element;
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BaseContentBuilder<B extends BaseContentBuilder<B>> {
public int stageId = 0;
public String identifier;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public BaseContentBuilder() {
this.stageId = 0;
this.identifier = Externalization.EMPTY_STRING;
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize. This constructor will add all associated handles as keys in
* the position map.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public BaseContentBuilder(Element rootElement) throws BuildException {
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize. This constructor will add all associated handles as keys in
* the position map.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @param context
* @param callback
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public BaseContentBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
identifier = BootstrappingUtils.getContentAsString(rootElement, Externalization.IDENTIFIER_NODE, BootstrappingUtils.MANDATORY, null, context);
stageId = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STAGE_ID_NODE, BootstrappingUtils.OPTIONAL, 0, context);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public abstract Content build() throws BuildException;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.content.builder;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
* @param <B>
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class ContentBuilder<B extends ContentBuilder<B>> extends BaseContentBuilder<B> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public ContentBuilder() {
super();
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public ContentBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public ContentBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public Content build() throws BuildException {
// TODO Auto-generated method stub
return null;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
VERSION=${project.version}
BUILD_DATE=${buildNumber}
\ No newline at end of file
......@@ -60,6 +60,7 @@ public class Externalization extends NLS {
public static String COLOUR_NODE;
public static String COLOURSC_NODE;
public static String CONNECTIONS_NODE;
public static String CONTENT_BUILDER_NAMESPACE;
public static String CORNER_RADIUS_NODE;
public static String CORONA_BUILDER_NAMESPACE;
public static String CORONA_NODE;
......@@ -102,6 +103,7 @@ public class Externalization extends NLS {
public static String HANDLES_NODE;
public static String HEIGHT_NODE;
public static String HTML_CONTENT_NODE;
public static String IDENTIFIER_NODE;
public static String IMAGE_BASE64_ELEMENT;
public static String IMAGE_ELEMENT;
public static String IMAGES_ELEMENT;
......
Markdown is supported
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