# added serialization of base domain objects to shared (server + apps) bundle

This commit is contained in:
Lukas Niemeier committed 2013-01-02 19:55:45 +01:00
1 parent 4cc0741166
commit 2c841ccd5a
15 files changed
+261 -2

No files matched your search

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.sap.sailing.server.gateway.serialization</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Serialization
Bundle-SymbolicName: com.sap.sailing.server.gateway.serialization
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: SAP
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.json.simple
Require-Bundle: com.sap.sailing.domain;bundle-version="1.0.0",
com.sap.sailing.domain.common;bundle-version="1.0.0"
Export-Package: com.sap.sailing.server.gateway.serialization
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,16 @@
package com.sap.sailing.server.gateway.serialization;
import org.json.simple.JSONObject;
import com.sap.sailing.domain.base.BoatClass;
public class BoatClassJsonSerializer implements JsonSerializer<BoatClass> {
@Override
public JSONObject serialize(BoatClass object) {
JSONObject result = new JSONObject();
result.put("name", object.getName());
return result;
}
}
@@ -0,0 +1,27 @@
package com.sap.sailing.server.gateway.serialization;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.sap.sailing.domain.base.CourseArea;
import com.sap.sailing.domain.base.RaceDefinition;
public class CourseAreaJsonSerializer implements JsonSerializer<CourseArea>
{
@Override
public JSONObject serialize(CourseArea object) {
JSONObject result = new JSONObject();
result.put("name", object.getName());
JSONArray races = new JSONArray();
for (RaceDefinition race : object.getRaces())
{
races.add(race.getId().toString());
}
result.put("races", races);
return result;
}
}
@@ -0,0 +1,27 @@
package com.sap.sailing.server.gateway.serialization;
import org.json.simple.JSONObject;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.Venue;
public class EventJsonSerializer implements JsonSerializer<Event>
{
private JsonSerializer<Venue> venueSerializer;
public EventJsonSerializer(JsonSerializer<Venue> venueSerializer)
{
this.venueSerializer = venueSerializer;
}
public JSONObject serialize(Event object) {
JSONObject result = new JSONObject();
result.put("id", object.getId().toString());
result.put("name", object.getName());
result.put("publicationUrl", object.getPublicationUrl());
result.put("venue", venueSerializer.serialize(object.getVenue()));
return result;
}
}
@@ -0,0 +1,8 @@
package com.sap.sailing.server.gateway.serialization;
import org.json.simple.JSONObject;
public interface JsonSerializer<T>
{
JSONObject serialize(T object);
}
@@ -0,0 +1,20 @@
package com.sap.sailing.server.gateway.serialization;
import org.json.simple.JSONObject;
import com.sap.sailing.domain.base.RaceDefinition;
public class RaceDefinitionJsonSerializer implements JsonSerializer<RaceDefinition> {
@Override
public JSONObject serialize(RaceDefinition object) {
JSONObject result = new JSONObject();
result.put("id", object.getId().toString());
result.put("name", object.getName());
result.put("course", "tbd");
return result;
}
}
@@ -0,0 +1,41 @@
package com.sap.sailing.server.gateway.serialization;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.sap.sailing.domain.base.BoatClass;
import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.base.Regatta;
public class RegattaJsonSerializer implements JsonSerializer<Regatta> {
private JsonSerializer<BoatClass> boatClassSerializer;
private JsonSerializer<RaceDefinition> raceDefinitionSerializer;
public RegattaJsonSerializer(
JsonSerializer<BoatClass> boatClassSerializer,
JsonSerializer<RaceDefinition> raceDefinitionSerializer)
{
this.boatClassSerializer = boatClassSerializer;
this.raceDefinitionSerializer = raceDefinitionSerializer;
}
@Override
public JSONObject serialize(Regatta object) {
JSONObject result = new JSONObject();
result.put("id", object.getId().toString());
result.put("baseName", object.getBaseName());
result.put("boatClass", boatClassSerializer.serialize(object.getBoatClass()));
JSONArray races = new JSONArray();
for (RaceDefinition race : object.getAllRaces())
{
races.add(raceDefinitionSerializer.serialize(race));
}
result.put("races", races);
return result;
}
}
@@ -0,0 +1,34 @@
package com.sap.sailing.server.gateway.serialization;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.sap.sailing.domain.base.CourseArea;
import com.sap.sailing.domain.base.Venue;
public class VenueJsonSerializer implements JsonSerializer<Venue>
{
private JsonSerializer<CourseArea> areaSerializer;
public VenueJsonSerializer(JsonSerializer<CourseArea> areaSerializer)
{
this.areaSerializer = areaSerializer;
}
@Override
public JSONObject serialize(Venue object) {
JSONObject result = new JSONObject();
result.put("name", object.getName());
JSONArray areas = new JSONArray();
for (CourseArea area : object.getCourseAreas())
{
areas.add(areaSerializer.serialize(area));
}
result.put("courseAreas", areas);
return result;
}
}