You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2016/04/12 09:08:30 UTC
[4/8] isis git commit: ISIS-1373: isis-core-applib now depends on
isis-core-schema,
rather than other way around. Moved JaxbServiceDefault to applib.
ISIS-1373: isis-core-applib now depends on isis-core-schema, rather than other way around. Moved JaxbServiceDefault to applib.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/4967495f
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/4967495f
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/4967495f
Branch: refs/heads/ISIS-1291
Commit: 4967495f381ee9f565a9c1cb63a08bd0dbcd1653
Parents: efdb1d4
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Apr 12 00:12:01 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Apr 12 00:12:01 2016 +0100
----------------------------------------------------------------------
core/applib/pom.xml | 4 +-
.../services/jaxb/JaxbServiceDefault.java | 49 ++
.../utils/ActionInvocationMementoDtoUtils.java | 567 +++++++++++++++++++
.../jaxbadapters/PersistentEntityAdapter.java | 68 +++
.../org/apache/isis/schema/utils/Roundtrip.java | 312 ++++++++++
core/schema/pom.xml | 4 +-
.../services/jaxb/JaxbServiceDefault.java | 49 --
.../utils/ActionInvocationMementoDtoUtils.java | 566 ------------------
.../jaxbadapters/PersistentEntityAdapter.java | 68 ---
.../org/apache/isis/schema/utils/Roundtrip.java | 311 ----------
10 files changed, 1000 insertions(+), 998 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/applib/pom.xml
----------------------------------------------------------------------
diff --git a/core/applib/pom.xml b/core/applib/pom.xml
index 1a6796c..4cb78cd 100644
--- a/core/applib/pom.xml
+++ b/core/applib/pom.xml
@@ -90,8 +90,8 @@
<dependencies>
<dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-schema</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/applib/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java b/core/applib/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java
new file mode 100644
index 0000000..3679fdb
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.schema.services.jaxb;
+
+import javax.inject.Inject;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.services.jaxb.JaxbService;
+import org.apache.isis.schema.utils.jaxbadapters.PersistentEntityAdapter;
+
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
+public class JaxbServiceDefault extends JaxbService.Simple {
+
+ protected void configure(final Unmarshaller unmarshaller) {
+ final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
+ container.injectServicesInto(adapter);
+ unmarshaller.setAdapter(PersistentEntityAdapter.class, adapter);
+ }
+
+ protected void configure(final Marshaller marshaller) {
+ final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
+ container.injectServicesInto(adapter);
+ marshaller.setAdapter(PersistentEntityAdapter.class, adapter);
+ }
+
+ @Inject
+ DomainObjectContainer container;
+}
+
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/applib/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java b/core/applib/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java
new file mode 100644
index 0000000..3f6db44
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java
@@ -0,0 +1,567 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.schema.utils;
+
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import com.google.common.base.Function;
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.io.Resources;
+
+import org.joda.time.DateTime;
+import org.joda.time.LocalDate;
+import org.joda.time.LocalDateTime;
+import org.joda.time.LocalTime;
+
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.schema.aim.v1.ActionInvocationMementoDto;
+import org.apache.isis.schema.aim.v1.ParamDto;
+import org.apache.isis.schema.common.v1.BookmarkObjectState;
+import org.apache.isis.schema.common.v1.OidDto;
+import org.apache.isis.schema.common.v1.ValueDto;
+import org.apache.isis.schema.common.v1.ValueType;
+import org.apache.isis.schema.utils.jaxbadapters.JavaSqlTimestampXmlGregorianCalendarAdapter;
+import org.apache.isis.schema.utils.jaxbadapters.JodaDateTimeXMLGregorianCalendarAdapter;
+import org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateTimeXMLGregorianCalendarAdapter;
+import org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateXMLGregorianCalendarAdapter;
+import org.apache.isis.schema.utils.jaxbadapters.JodaLocalTimeXMLGregorianCalendarAdapter;
+
+public final class ActionInvocationMementoDtoUtils {
+
+ //region > static
+ private static final Function<ParamDto, String> PARAM_DTO_TO_NAME = new Function<ParamDto, String>() {
+ @Override public String apply(final ParamDto input) {
+ return input.getParameterName();
+ }
+ };
+ private static final Function<ParamDto, ValueType> PARAM_DTO_TO_TYPE = new Function<ParamDto, ValueType>() {
+ @Override public ValueType apply(final ParamDto input) {
+ return input.getParameterType();
+ }
+ };
+ private static JAXBContext jaxbContext;
+ private static JAXBContext getJaxbContext() {
+ if(jaxbContext == null) {
+ try {
+ jaxbContext = JAXBContext.newInstance(ActionInvocationMementoDto.class);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return jaxbContext;
+ }
+ //endregion
+
+ public static ActionInvocationMementoDto newDto() {
+ return new ActionInvocationMementoDto();
+ }
+
+ //region > actionIdentifier, target
+
+ public static void setMetadata(
+ final ActionInvocationMementoDto aim,
+ final UUID transactionId,
+ final int sequence,
+ final Timestamp timestamp,
+ final String targetClass,
+ final String targetAction,
+ final String actionIdentifier,
+ final String targetObjectType,
+ final String targetObjectIdentifier,
+ final String title,
+ final String user) {
+ ActionInvocationMementoDto.Metadata metadata = aim.getMetadata();
+ if(metadata == null) {
+ metadata = new ActionInvocationMementoDto.Metadata();
+ aim.setMetadata(metadata);
+ }
+
+ metadata.setTransactionId(transactionId.toString());
+ metadata.setSequence(sequence);
+ metadata.setTimestamp(JavaSqlTimestampXmlGregorianCalendarAdapter.print(timestamp));
+
+ metadata.setTargetClass(targetClass);
+ metadata.setTargetAction(targetAction);
+ metadata.setActionIdentifier(actionIdentifier);
+
+ final OidDto target = new OidDto();
+ target.setObjectType(targetObjectType);
+ target.setObjectIdentifier(targetObjectIdentifier);
+ metadata.setTarget(target);
+
+ metadata.setTitle(title);
+ metadata.setUser(user);
+ }
+
+
+ //endregion
+
+ //region > addArgValue, addArgReference
+ public static boolean addArgValue(
+ final ActionInvocationMementoDto aim,
+ final String parameterName,
+ final Class<?> parameterType,
+ final Object arg) {
+
+ ParamDto paramDto = null;
+ if(parameterType == String.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.STRING, arg);
+ } else
+ if(parameterType == byte.class || parameterType == Byte.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.BYTE, arg);
+ } else
+ if(parameterType == short.class || parameterType == Short.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.SHORT, arg);
+ }else
+ if(parameterType == int.class || parameterType == Integer.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.INT, arg);
+ }else
+ if(parameterType == long.class || parameterType == Long.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.LONG, arg);
+ }else
+ if(parameterType == char.class || parameterType == Character.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.CHAR, arg);
+ }else
+ if(parameterType == boolean.class || parameterType == Boolean.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.BOOLEAN, arg);
+ }else
+ if(parameterType == float.class || parameterType == Float.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.FLOAT, arg);
+ }else
+ if(parameterType == double.class || parameterType == Double.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.DOUBLE, arg);
+ }else
+ if(parameterType == BigInteger.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.BIG_INTEGER, arg);
+ }else
+ if(parameterType == BigDecimal.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.BIG_DECIMAL, arg);
+ }else
+ if(parameterType == DateTime.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.JODA_DATE_TIME, arg);
+ }else
+ if(parameterType == LocalDateTime.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.JODA_LOCAL_DATE_TIME, arg);
+ }else
+ if(parameterType == LocalDate.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.JODA_LOCAL_DATE, arg);
+ }else
+ if(parameterType == LocalTime.class) {
+ paramDto = newParamDto(aim, parameterName, ValueType.JODA_LOCAL_TIME, arg);
+ }
+
+ if(paramDto != null) {
+ final ValueDto valueDto = valueDtoFor(paramDto);
+ setValue(valueDto, parameterType, arg);
+ return true;
+ }
+
+ // none of the supported value types
+ return false;
+ }
+
+
+ public static void addArgReference(
+ final ActionInvocationMementoDto aim,
+ final String parameterName,
+ final Bookmark bookmark) {
+ final ParamDto paramDto = newParamDto(aim, parameterName, ValueType.REFERENCE, bookmark);
+ final ValueDto valueDto = valueDtoFor(paramDto);
+ OidDto argValue = asOidDto(bookmark);
+ valueDto.setReference(argValue);
+ }
+
+
+ private static OidDto asOidDto(final Bookmark reference) {
+ OidDto argValue;
+ if(reference != null) {
+ argValue = new OidDto();
+ argValue.setObjectType(reference.getObjectType());
+ argValue.setObjectState(bookmarkObjectStateOf(reference));
+ argValue.setObjectIdentifier(reference.getIdentifier());
+ } else {
+ argValue = null;
+ }
+ return argValue;
+ }
+
+ private static BookmarkObjectState bookmarkObjectStateOf(final Bookmark reference) {
+ switch(reference.getObjectState()) {
+ case PERSISTENT: return BookmarkObjectState.PERSISTENT;
+ case TRANSIENT: return BookmarkObjectState.TRANSIENT;
+ case VIEW_MODEL: return BookmarkObjectState.VIEW_MODEL;
+ }
+ throw new IllegalArgumentException(String.format("reference.objectState '%s' not recognized", reference.getObjectState()));
+ }
+
+ private static ParamDto newParamDto(
+ final ActionInvocationMementoDto aim,
+ final String parameterName,
+ final ValueType parameterType, final Object value) {
+ final ActionInvocationMementoDto.Payload.Parameters params = getParametersHolderAutoCreate(aim);
+ final ParamDto paramDto = newParamDto(parameterName, parameterType);
+ paramDto.setNull(value == null);
+ addParamNum(params, paramDto);
+ return paramDto;
+ }
+
+ // lazily creates if required
+ private static ValueDto valueDtoFor(final ParamDto paramDto) {
+ ValueDto valueDto = paramDto.getValue();
+ if(valueDto == null) {
+ valueDto = new ValueDto();
+ }
+ paramDto.setValue(valueDto);
+ return valueDto;
+ }
+
+ private static ParamDto newParamDto(final String parameterName, final ValueType parameterType) {
+ final ParamDto argDto = new ParamDto();
+ argDto.setParameterName(parameterName);
+ argDto.setParameterType(parameterType);
+ return argDto;
+ }
+
+ //endregion
+
+ //region > addReturnValue, addReturnReference
+ public static boolean addReturnValue(
+ final ActionInvocationMementoDto aim,
+ final Class<?> returnType,
+ final Object returnVal) {
+ final ValueDto valueDto = returnValueDtoFor(aim);
+ return setValue(valueDto, returnType, returnVal);
+ }
+
+ public static void addReturnReference(
+ final ActionInvocationMementoDto aim,
+ final Bookmark bookmark) {
+ final ValueDto valueDto = returnValueDtoFor(aim);
+ OidDto argValue = asOidDto(bookmark);
+ valueDto.setReference(argValue);
+ }
+
+ //endregion
+
+
+
+
+ //region > getNumberOfParameters, getParameters, getParameterNames, getParameterTypes
+ public static int getNumberOfParameters(final ActionInvocationMementoDto aim) {
+ final ActionInvocationMementoDto.Payload.Parameters params = getParametersHolderElseThrow(aim);
+ if(params == null) {
+ return 0;
+ }
+ return params.getNum();
+ }
+ public static List<ParamDto> getParameters(final ActionInvocationMementoDto aim) {
+ final ActionInvocationMementoDto.Payload.Parameters params = getParametersHolderElseThrow(aim);
+ final int parameterNumber = getNumberOfParameters(aim);
+ final List<ParamDto> paramDtos = Lists.newArrayList();
+ for (int i = 0; i < parameterNumber; i++) {
+ final ParamDto paramDto = params.getParam().get(i);
+ paramDtos.add(paramDto);
+ }
+ return Collections.unmodifiableList(paramDtos);
+ }
+ public static List<String> getParameterNames(final ActionInvocationMementoDto aim) {
+ return immutableList(Iterables.transform(getParameters(aim), PARAM_DTO_TO_NAME));
+ }
+ public static List<ValueType> getParameterTypes(final ActionInvocationMementoDto aim) {
+ return immutableList(Iterables.transform(getParameters(aim), PARAM_DTO_TO_TYPE));
+ }
+ //endregion
+
+ //region > getParameter, getParameterName, getParameterType
+ public static ParamDto getParameter(final ActionInvocationMementoDto aim, final int paramNum) {
+ final int parameterNumber = getNumberOfParameters(aim);
+ if(paramNum > parameterNumber) {
+ throw new IllegalArgumentException(String.format("No such parameter %d (the memento has %d parameters)", paramNum, parameterNumber));
+ }
+ final List<ParamDto> parameters = getParameters(aim);
+ return parameters.get(paramNum);
+ }
+
+ public static ValueDto getParameterValue(final ActionInvocationMementoDto aim, final int paramNum) {
+ final ParamDto paramDto = getParameter(aim, paramNum);
+ return valueDtoFor(paramDto);
+ }
+
+
+ public static String getParameterName(final ActionInvocationMementoDto aim, final int paramNum) {
+ return PARAM_DTO_TO_NAME.apply(getParameter(aim, paramNum));
+ }
+ public static ValueType getParameterType(final ActionInvocationMementoDto aim, final int paramNum) {
+ return PARAM_DTO_TO_TYPE.apply(getParameter(aim, paramNum));
+ }
+ public static boolean isNull(final ActionInvocationMementoDto aim, int paramNum) {
+ final ParamDto paramDto = getParameter(aim, paramNum);
+ return paramDto.isNull();
+ }
+ //endregion
+
+ //region > getArg
+ public static <T> T getArg(final ActionInvocationMementoDto aim, int paramNum, Class<T> cls) {
+ final ParamDto paramDto = getParameter(aim, paramNum);
+ if(paramDto.isNull()) {
+ return null;
+ }
+ final ValueDto valueDto = valueDtoFor(paramDto);
+ final ValueType parameterType = paramDto.getParameterType();
+ switch(parameterType) {
+ case STRING:
+ return (T) valueDto.getString();
+ case BYTE:
+ return (T) valueDto.getByte();
+ case SHORT:
+ return (T) valueDto.getShort();
+ case INT:
+ return (T) valueDto.getInt();
+ case LONG:
+ return (T) valueDto.getLong();
+ case FLOAT:
+ return (T) valueDto.getFloat();
+ case DOUBLE:
+ return (T) valueDto.getDouble();
+ case BOOLEAN:
+ return (T) valueDto.isBoolean();
+ case CHAR:
+ final String aChar = valueDto.getChar();
+ if(Strings.isNullOrEmpty(aChar)) { return null; }
+ return (T) (Object)aChar.charAt(0);
+ case BIG_DECIMAL:
+ return (T) valueDto.getBigDecimal();
+ case BIG_INTEGER:
+ return (T) valueDto.getBigInteger();
+ case JODA_DATE_TIME:
+ return (T) JodaDateTimeXMLGregorianCalendarAdapter.parse(valueDto.getDateTime());
+ case JODA_LOCAL_DATE:
+ return (T) JodaLocalDateXMLGregorianCalendarAdapter.parse(valueDto.getLocalDate());
+ case JODA_LOCAL_DATE_TIME:
+ return (T) JodaLocalDateTimeXMLGregorianCalendarAdapter.parse(valueDto.getLocalDateTime());
+ case JODA_LOCAL_TIME:
+ return (T) JodaLocalTimeXMLGregorianCalendarAdapter.parse(valueDto.getLocalTime());
+ case REFERENCE:
+ return (T) valueDto.getReference();
+ }
+ throw new IllegalStateException("Parameter type was not recognised (possible bug)");
+ }
+ //endregion
+
+ //region > marshalling
+ public static ActionInvocationMementoDto fromXml(Reader reader) {
+ Unmarshaller un = null;
+ try {
+ un = getJaxbContext().createUnmarshaller();
+ return (ActionInvocationMementoDto) un.unmarshal(reader);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static ActionInvocationMementoDto fromXml(
+ final Class<?> contextClass,
+ final String resourceName,
+ final Charset charset) throws IOException {
+ final URL url = Resources.getResource(contextClass, resourceName);
+ final String s = Resources.toString(url, charset);
+ return fromXml(new StringReader(s));
+ }
+
+ public static String toXml(final ActionInvocationMementoDto aim) {
+ final CharArrayWriter caw = new CharArrayWriter();
+ toXml(aim, caw);
+ return caw.toString();
+ }
+
+ public static void toXml(final ActionInvocationMementoDto aim, final Writer writer) {
+ Marshaller m = null;
+ try {
+ m = getJaxbContext().createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ m.marshal(aim, writer);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ //endregion
+
+ //region > debugging
+ public static void dump(final ActionInvocationMementoDto aim, final PrintStream out) throws JAXBException {
+ out.println(toXml(aim));
+ }
+ //endregion
+
+ //region > helpers
+ private static void addParamNum(final ActionInvocationMementoDto.Payload.Parameters params, final ParamDto arg) {
+ params.getParam().add(arg);
+ Integer num = params.getNum();
+ if(num == null) {
+ num = 0;
+ }
+ params.setNum(num +1);
+ }
+
+ private static ActionInvocationMementoDto.Payload.Parameters getParametersHolderElseThrow(final ActionInvocationMementoDto aim) {
+ final ActionInvocationMementoDto.Payload payload = getPayloadElseThrow(aim);
+ final ActionInvocationMementoDto.Payload.Parameters parameters = payload.getParameters();
+ if(parameters == null) {
+ throw new IllegalStateException("No parameters have been added");
+ }
+ return parameters;
+ }
+
+ private static ActionInvocationMementoDto.Payload.Parameters getParametersHolderAutoCreate(final ActionInvocationMementoDto aim) {
+ final ActionInvocationMementoDto.Payload payload = getPayloadAutoCreate(aim);
+ ActionInvocationMementoDto.Payload.Parameters params = payload.getParameters();
+ if(params == null) {
+ params = new ActionInvocationMementoDto.Payload.Parameters();
+ payload.setParameters(params);
+ }
+ return params;
+ }
+
+ private static ValueDto returnValueDtoFor(final ActionInvocationMementoDto aim) {
+ final ActionInvocationMementoDto.Payload payload = getPayloadAutoCreate(aim);
+ ValueDto valueDto = payload.getReturn();
+ if(valueDto == null) {
+ valueDto = new ValueDto();
+ payload.setReturn(valueDto);
+ }
+ return valueDto;
+ }
+
+ private static ActionInvocationMementoDto.Payload getPayloadAutoCreate(final ActionInvocationMementoDto aim) {
+ ActionInvocationMementoDto.Payload payload = aim.getPayload();
+ if(payload == null) {
+ payload = new ActionInvocationMementoDto.Payload();
+ aim.setPayload(payload);
+ }
+ return payload;
+ }
+
+ private static ActionInvocationMementoDto.Payload getPayloadElseThrow(final ActionInvocationMementoDto aim) {
+ ActionInvocationMementoDto.Payload payload = aim.getPayload();
+ if(payload == null) {
+ throw new IllegalStateException("No payload has been added");
+ }
+ return payload;
+ }
+
+ private static <T> List<T> immutableList(final Iterable<T> transform) {
+ return Collections.unmodifiableList(
+ Lists.newArrayList(
+ transform
+ )
+ );
+ }
+
+
+ private static boolean setValue(final ValueDto valueDto, final Class<?> type, final Object returnVal) {
+ if(type == String.class) {
+ final String argValue = (String) returnVal;
+ valueDto.setString(argValue);
+ } else
+ if(type == byte.class || type == Byte.class) {
+ final Byte argValue = (Byte) returnVal;
+ valueDto.setByte(argValue);
+ } else
+ if(type == short.class || type == Short.class) {
+ final Short argValue = (Short) returnVal;
+ valueDto.setShort(argValue);
+ }else
+ if(type == int.class || type == Integer.class) {
+ final Integer argValue = (Integer) returnVal;
+ valueDto.setInt(argValue);
+ }else
+ if(type == long.class || type == Long.class) {
+ final Long argValue = (Long) returnVal;
+ valueDto.setLong(argValue);
+ }else
+ if(type == char.class || type == Character.class) {
+ final Character argValue = (Character) returnVal;
+ valueDto.setChar("" + argValue);
+ }else
+ if(type == boolean.class || type == Boolean.class) {
+ final Boolean argValue = (Boolean) returnVal;
+ valueDto.setBoolean(argValue);
+ }else
+ if(type == float.class || type == Float.class) {
+ final Float argValue = (Float) returnVal;
+ valueDto.setFloat(argValue);
+ }else
+ if(type == double.class || type == Double.class) {
+ final Double argValue = (Double) returnVal;
+ valueDto.setDouble(argValue);
+ }else
+ if(type == BigInteger.class) {
+ final BigInteger argValue = (BigInteger) returnVal;
+ valueDto.setBigInteger(argValue);
+ }else
+ if(type == BigDecimal.class) {
+ final BigDecimal argValue = (BigDecimal) returnVal;
+ valueDto.setBigDecimal(argValue);
+ }else
+ if(type == DateTime.class) {
+ final DateTime argValue = (DateTime) returnVal;
+ valueDto.setDateTime(JodaDateTimeXMLGregorianCalendarAdapter.print(argValue));
+ }else
+ if(type == LocalDateTime.class) {
+ final LocalDateTime argValue = (LocalDateTime) returnVal;
+ valueDto.setLocalDateTime(JodaLocalDateTimeXMLGregorianCalendarAdapter.print(argValue));
+ }else
+ if(type == LocalDate.class) {
+ final LocalDate argValue = (LocalDate) returnVal;
+ valueDto.setLocalDate(JodaLocalDateXMLGregorianCalendarAdapter.print(argValue));
+ }else
+ if(type == LocalTime.class) {
+ final LocalTime argValue = (LocalTime) returnVal;
+ valueDto.setLocalTime(JodaLocalTimeXMLGregorianCalendarAdapter.print(argValue));
+ }else
+ {
+ // none of the supported value types
+ return false;
+ }
+ return true;
+ }
+
+ //endregion
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/applib/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java b/core/applib/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
new file mode 100644
index 0000000..e88576a
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.schema.utils.jaxbadapters;
+
+import javax.inject.Inject;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.bookmark.BookmarkService;
+import org.apache.isis.applib.services.bookmark.BookmarkService2;
+import org.apache.isis.schema.common.v1.BookmarkObjectState;
+import org.apache.isis.schema.common.v1.OidDto;
+
+public class PersistentEntityAdapter extends XmlAdapter<OidDto, Object> {
+
+ @Override
+ public Object unmarshal(final OidDto oidDto) throws Exception {
+
+ final String objectType = oidDto.getObjectType();
+ final String identifier = oidDto.getObjectIdentifier();
+ final Bookmark bookmark = new Bookmark(objectType, identifier);
+
+ return bookmarkService.lookup(bookmark, BookmarkService2.FieldResetPolicy.DONT_RESET);
+ }
+
+ @Override
+ public OidDto marshal(final Object domainObject) throws Exception {
+ if(domainObject == null) {
+ return null;
+ }
+ final Bookmark bookmark = getBookmarkService().bookmarkFor(domainObject);
+ final OidDto oidDto = new OidDto();
+ oidDto.setObjectIdentifier(bookmark.getIdentifier());
+ oidDto.setObjectState(convert(bookmark.getObjectState()));
+ oidDto.setObjectType(bookmark.getObjectType());
+ return oidDto;
+ }
+
+ private BookmarkObjectState convert(final Bookmark.ObjectState objectState) {
+ switch (objectState) {
+ case VIEW_MODEL:return BookmarkObjectState.VIEW_MODEL;
+ case TRANSIENT:return BookmarkObjectState.TRANSIENT;
+ case PERSISTENT:return BookmarkObjectState.PERSISTENT;
+ }
+ throw new IllegalArgumentException("Not recognized: " + objectState.name());
+ }
+
+ protected BookmarkService getBookmarkService() {
+ return bookmarkService;
+ }
+
+ @Inject
+ BookmarkService2 bookmarkService;
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/applib/src/test/java/org/apache/isis/schema/utils/Roundtrip.java
----------------------------------------------------------------------
diff --git a/core/applib/src/test/java/org/apache/isis/schema/utils/Roundtrip.java b/core/applib/src/test/java/org/apache/isis/schema/utils/Roundtrip.java
new file mode 100644
index 0000000..bc8a44d
--- /dev/null
+++ b/core/applib/src/test/java/org/apache/isis/schema/utils/Roundtrip.java
@@ -0,0 +1,312 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.schema.utils;
+
+import java.io.CharArrayReader;
+import java.io.CharArrayWriter;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.UUID;
+
+import org.hamcrest.Matchers;
+import org.joda.time.DateTime;
+import org.joda.time.LocalDate;
+import org.joda.time.LocalDateTime;
+import org.joda.time.LocalTime;
+import org.junit.Test;
+
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.schema.aim.v1.ActionInvocationMementoDto;
+import org.apache.isis.schema.common.v1.OidDto;
+import org.apache.isis.schema.common.v1.ValueType;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class Roundtrip {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ final ActionInvocationMementoDto aim = ActionInvocationMementoDtoUtils.newDto();
+
+ ActionInvocationMementoDtoUtils.setMetadata(
+ aim,
+ UUID.randomUUID(),
+ 1,
+ new java.sql.Timestamp(new java.util.Date().getTime()),
+ "com.mycompany.myapp.Customer", "placeOrder", "com.mycompany.myapp.Customer#placeOrder",
+ "CUS", "12345", "John Customer", "freddyUser");
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aString", String.class, "Fred");
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullString", String.class, (String) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aByte", Byte.class, (Byte) (byte) 123);
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullByte", Byte.class, (Byte) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aShort", Short.class, (Short) (short) 32123);
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullShort", Short.class, (Short) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "anInt", Integer.class, 123454321);
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullInt", Integer.class, (Integer) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aLong", Long.class, 1234567654321L);
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullLong", Long.class, (Long) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aFloat", Float.class, 12345.6789F);
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullFloat", Float.class, (Float) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aDouble", Double.class, 12345678.90123);
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullDouble", Double.class, (Double) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aBoolean", Boolean.class, true);
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullBoolean", Boolean.class, (Boolean) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aChar", Character.class, 'x');
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullChar", Character.class, (Character) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aBigInteger", java.math.BigInteger.class, new java.math.BigInteger("12345678901234567890"));
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullBigInteger", java.math.BigInteger.class, (java.math.BigInteger) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aBigDecimal", java.math.BigDecimal.class, new java.math.BigDecimal("12345678901234567890"));
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullBigDecimal", java.math.BigDecimal.class, (java.math.BigDecimal) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aJodaDateTime", org.joda.time.DateTime.class, new org.joda.time.DateTime(2015, 5, 23, 9, 54, 1));
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullJodaDateTime", org.joda.time.DateTime.class, (org.joda.time.DateTime) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aJodaLocalDate", org.joda.time.LocalDate.class, new org.joda.time.LocalDate(2015, 5, 23));
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullJodaLocalDate", org.joda.time.LocalDate.class, (org.joda.time.LocalDate) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aJodaLocalDateTime", org.joda.time.LocalDateTime.class, new org.joda.time.LocalDateTime(2015, 5, 23, 9, 54, 1));
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullJodaLocalDateTime", org.joda.time.LocalDateTime.class, (org.joda.time.LocalDateTime) null);
+
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "aJodaLocalTime", org.joda.time.LocalTime.class, new org.joda.time.LocalTime(9, 54, 1));
+ ActionInvocationMementoDtoUtils.addArgValue(aim, "nullJodaLocalTime", org.joda.time.LocalTime.class, (org.joda.time.LocalTime) null);
+
+ ActionInvocationMementoDtoUtils.addArgReference(aim, "aReference", new Bookmark("ORD", "12345"));
+ ActionInvocationMementoDtoUtils.addArgReference(aim, "nullReference", null);
+
+
+ // when
+ final CharArrayWriter caw = new CharArrayWriter();
+ ActionInvocationMementoDtoUtils.toXml(aim, caw);
+
+ ActionInvocationMementoDtoUtils.dump(aim, System.out);
+
+ final CharArrayReader reader = new CharArrayReader(caw.toCharArray());
+ final ActionInvocationMementoDto recreated = ActionInvocationMementoDtoUtils.fromXml(reader);
+
+
+ // then
+ assertThat(recreated.getMetadata().getActionIdentifier(), Matchers.is(aim.getMetadata().getActionIdentifier()));
+ assertThat(recreated.getMetadata().getTarget().getObjectType(), Matchers.is(aim.getMetadata().getTarget().getObjectType()));
+ assertThat(recreated.getMetadata().getTarget().getObjectIdentifier(), Matchers.is(aim.getMetadata().getTarget().getObjectIdentifier()));
+
+
+ int param = 0;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aString"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.STRING));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, String.class), is("Fred"));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullString"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.STRING));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, String.class), is(nullValue()));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aByte"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BYTE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, Byte.class), is((byte) 123));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BYTE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullByte"));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aShort"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.SHORT));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, Short.class), is((short) 32123));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullShort"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.SHORT));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("anInt"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.INT));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, int.class), is((int) 123454321));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullInt"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.INT));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aLong"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.LONG));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, long.class), is((long) 1234567654321L));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullLong"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.LONG));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aFloat"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.FLOAT));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, float.class), is((float) 12345.6789F));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullFloat"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.FLOAT));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aDouble"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.DOUBLE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, double.class), is(12345678.90123));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullDouble"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.DOUBLE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aBoolean"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BOOLEAN));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, boolean.class), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullBoolean"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BOOLEAN));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aChar"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.CHAR));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, char.class), is('x'));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullChar"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.CHAR));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aBigInteger"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BIG_INTEGER));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, BigInteger.class), is(new java.math.BigInteger("12345678901234567890")));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullBigInteger"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BIG_INTEGER));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aBigDecimal"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BIG_DECIMAL));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, BigDecimal.class), is(new java.math.BigDecimal("12345678901234567890")));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullBigDecimal"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.BIG_DECIMAL));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aJodaDateTime"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_DATE_TIME));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ // bit hacky... regular comparison fails but toString() works... must be some additional data that differs, not sure what tho'
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, DateTime.class).toString(), is(new DateTime(2015, 5, 23, 9, 54, 1).toString()));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullJodaDateTime"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_DATE_TIME));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));;
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aJodaLocalDate"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_LOCAL_DATE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ final LocalDate actual = ActionInvocationMementoDtoUtils.getArg(recreated, param, LocalDate.class);
+ final LocalDate expected = new LocalDate(2015, 5, 23);
+ assertThat(actual, equalTo(expected));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullJodaLocalDate"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_LOCAL_DATE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aJodaLocalDateTime"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_LOCAL_DATE_TIME));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, LocalDateTime.class), is(new org.joda.time.LocalDateTime(2015, 5, 23, 9, 54, 1)));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullJodaLocalDateTime"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_LOCAL_DATE_TIME));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aJodaLocalTime"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_LOCAL_TIME));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, LocalTime.class), is(new org.joda.time.LocalTime(9, 54, 1)));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullJodaLocalTime"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.JODA_LOCAL_TIME));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("aReference"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.REFERENCE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(false));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, OidDto.class).getObjectType(), is("ORD"));
+ assertThat(ActionInvocationMementoDtoUtils.getArg(recreated, param, OidDto.class).getObjectIdentifier(), is("12345"));
+
+ param++;
+ assertThat(ActionInvocationMementoDtoUtils.getParameterName(recreated, param), is("nullReference"));
+ assertThat(ActionInvocationMementoDtoUtils.getParameterType(recreated, param), Matchers.is(ValueType.REFERENCE));
+ assertThat(ActionInvocationMementoDtoUtils.isNull(recreated, param), is(true));
+
+ param++;
+// final int expected = param;
+// assertThat(recreated.getParameters().getNum(), is(expected);
+// assertThat(recreated.getParameters().getParam().size(), is(expected);
+// assertThat(ActionInvocationMementoDtoUtils.getNumberOfParameters(recreated), is(expected);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/schema/pom.xml
----------------------------------------------------------------------
diff --git a/core/schema/pom.xml b/core/schema/pom.xml
index a05eac2..cda7e43 100644
--- a/core/schema/pom.xml
+++ b/core/schema/pom.xml
@@ -36,8 +36,8 @@
<dependencies>
<dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-applib</artifactId>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/schema/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/schema/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java b/core/schema/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java
deleted file mode 100644
index 3679fdb..0000000
--- a/core/schema/src/main/java/org/apache/isis/schema/services/jaxb/JaxbServiceDefault.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.schema.services.jaxb;
-
-import javax.inject.Inject;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-
-import org.apache.isis.applib.DomainObjectContainer;
-import org.apache.isis.applib.annotation.DomainService;
-import org.apache.isis.applib.annotation.NatureOfService;
-import org.apache.isis.applib.services.jaxb.JaxbService;
-import org.apache.isis.schema.utils.jaxbadapters.PersistentEntityAdapter;
-
-@DomainService(
- nature = NatureOfService.DOMAIN
-)
-public class JaxbServiceDefault extends JaxbService.Simple {
-
- protected void configure(final Unmarshaller unmarshaller) {
- final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
- container.injectServicesInto(adapter);
- unmarshaller.setAdapter(PersistentEntityAdapter.class, adapter);
- }
-
- protected void configure(final Marshaller marshaller) {
- final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
- container.injectServicesInto(adapter);
- marshaller.setAdapter(PersistentEntityAdapter.class, adapter);
- }
-
- @Inject
- DomainObjectContainer container;
-}
-
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/schema/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java
----------------------------------------------------------------------
diff --git a/core/schema/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java b/core/schema/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java
deleted file mode 100644
index 30128b2..0000000
--- a/core/schema/src/main/java/org/apache/isis/schema/utils/ActionInvocationMementoDtoUtils.java
+++ /dev/null
@@ -1,566 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.schema.utils;
-
-import java.io.CharArrayWriter;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.Writer;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.sql.Timestamp;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-
-import com.google.common.base.Function;
-import com.google.common.base.Strings;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.io.Resources;
-
-import org.joda.time.DateTime;
-import org.joda.time.LocalDate;
-import org.joda.time.LocalDateTime;
-import org.joda.time.LocalTime;
-
-import org.apache.isis.applib.services.bookmark.Bookmark;
-import org.apache.isis.schema.aim.v1.ActionInvocationMementoDto;
-import org.apache.isis.schema.aim.v1.ParamDto;
-import org.apache.isis.schema.common.v1.BookmarkObjectState;
-import org.apache.isis.schema.common.v1.OidDto;
-import org.apache.isis.schema.common.v1.ValueDto;
-import org.apache.isis.schema.common.v1.ValueType;
-import org.apache.isis.schema.utils.jaxbadapters.JavaSqlTimestampXmlGregorianCalendarAdapter;
-import org.apache.isis.schema.utils.jaxbadapters.JodaDateTimeXMLGregorianCalendarAdapter;
-import org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateTimeXMLGregorianCalendarAdapter;
-import org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateXMLGregorianCalendarAdapter;
-import org.apache.isis.schema.utils.jaxbadapters.JodaLocalTimeXMLGregorianCalendarAdapter;
-
-public final class ActionInvocationMementoDtoUtils {
-
- //region > static
- private static final Function<ParamDto, String> PARAM_DTO_TO_NAME = new Function<ParamDto, String>() {
- @Override public String apply(final ParamDto input) {
- return input.getParameterName();
- }
- };
- private static final Function<ParamDto, ValueType> PARAM_DTO_TO_TYPE = new Function<ParamDto, ValueType>() {
- @Override public ValueType apply(final ParamDto input) {
- return input.getParameterType();
- }
- };
- private static JAXBContext jaxbContext;
- private static JAXBContext getJaxbContext() {
- if(jaxbContext == null) {
- try {
- jaxbContext = JAXBContext.newInstance(ActionInvocationMementoDto.class);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- }
- return jaxbContext;
- }
- //endregion
-
- public static ActionInvocationMementoDto newDto() {
- return new ActionInvocationMementoDto();
- }
-
- //region > actionIdentifier, target
-
- public static void setMetadata(
- final ActionInvocationMementoDto aim,
- final UUID transactionId,
- final int sequence,
- final Timestamp timestamp,
- final String targetClass,
- final String targetAction,
- final String actionIdentifier,
- final String targetObjectType,
- final String targetObjectIdentifier,
- final String title,
- final String user) {
- ActionInvocationMementoDto.Metadata metadata = aim.getMetadata();
- if(metadata == null) {
- metadata = new ActionInvocationMementoDto.Metadata();
- aim.setMetadata(metadata);
- }
-
- metadata.setTransactionId(transactionId.toString());
- metadata.setSequence(sequence);
- metadata.setTimestamp(JavaSqlTimestampXmlGregorianCalendarAdapter.print(timestamp));
-
- metadata.setTargetClass(targetClass);
- metadata.setTargetAction(targetAction);
- metadata.setActionIdentifier(actionIdentifier);
-
- final OidDto target = new OidDto();
- target.setObjectType(targetObjectType);
- target.setObjectIdentifier(targetObjectIdentifier);
- metadata.setTarget(target);
-
- metadata.setTitle(title);
- metadata.setUser(user);
- }
-
-
- //endregion
-
- //region > addArgValue, addArgReference
- public static boolean addArgValue(
- final ActionInvocationMementoDto aim,
- final String parameterName,
- final Class<?> parameterType,
- final Object arg) {
-
- ParamDto paramDto = null;
- if(parameterType == String.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.STRING, arg);
- } else
- if(parameterType == byte.class || parameterType == Byte.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.BYTE, arg);
- } else
- if(parameterType == short.class || parameterType == Short.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.SHORT, arg);
- }else
- if(parameterType == int.class || parameterType == Integer.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.INT, arg);
- }else
- if(parameterType == long.class || parameterType == Long.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.LONG, arg);
- }else
- if(parameterType == char.class || parameterType == Character.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.CHAR, arg);
- }else
- if(parameterType == boolean.class || parameterType == Boolean.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.BOOLEAN, arg);
- }else
- if(parameterType == float.class || parameterType == Float.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.FLOAT, arg);
- }else
- if(parameterType == double.class || parameterType == Double.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.DOUBLE, arg);
- }else
- if(parameterType == BigInteger.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.BIG_INTEGER, arg);
- }else
- if(parameterType == BigDecimal.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.BIG_DECIMAL, arg);
- }else
- if(parameterType == DateTime.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.JODA_DATE_TIME, arg);
- }else
- if(parameterType == LocalDateTime.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.JODA_LOCAL_DATE_TIME, arg);
- }else
- if(parameterType == LocalDate.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.JODA_LOCAL_DATE, arg);
- }else
- if(parameterType == LocalTime.class) {
- paramDto = newParamDto(aim, parameterName, ValueType.JODA_LOCAL_TIME, arg);
- }
-
- if(paramDto != null) {
- final ValueDto valueDto = valueDtoFor(paramDto);
- setValue(valueDto, parameterType, arg);
- return true;
- }
-
- // none of the supported value types
- return false;
- }
-
-
- public static void addArgReference(
- final ActionInvocationMementoDto aim,
- final String parameterName,
- final Bookmark bookmark) {
- final ParamDto paramDto = newParamDto(aim, parameterName, ValueType.REFERENCE, bookmark);
- final ValueDto valueDto = valueDtoFor(paramDto);
- OidDto argValue = asOidDto(bookmark);
- valueDto.setReference(argValue);
- }
-
-
- private static OidDto asOidDto(final Bookmark reference) {
- OidDto argValue;
- if(reference != null) {
- argValue = new OidDto();
- argValue.setObjectType(reference.getObjectType());
- argValue.setObjectState(bookmarkObjectStateOf(reference));
- argValue.setObjectIdentifier(reference.getIdentifier());
- } else {
- argValue = null;
- }
- return argValue;
- }
-
- private static BookmarkObjectState bookmarkObjectStateOf(final Bookmark reference) {
- switch(reference.getObjectState()) {
- case PERSISTENT: return BookmarkObjectState.PERSISTENT;
- case TRANSIENT: return BookmarkObjectState.TRANSIENT;
- case VIEW_MODEL: return BookmarkObjectState.VIEW_MODEL;
- }
- throw new IllegalArgumentException(String.format("reference.objectState '%s' not recognized", reference.getObjectState()));
- }
-
- private static ParamDto newParamDto(
- final ActionInvocationMementoDto aim,
- final String parameterName,
- final ValueType parameterType, final Object value) {
- final ActionInvocationMementoDto.Payload.Parameters params = getParametersHolderAutoCreate(aim);
- final ParamDto paramDto = newParamDto(parameterName, parameterType);
- paramDto.setNull(value == null);
- addParamNum(params, paramDto);
- return paramDto;
- }
-
- // lazily creates if required
- private static ValueDto valueDtoFor(final ParamDto paramDto) {
- ValueDto valueDto = paramDto.getValue();
- if(valueDto == null) {
- valueDto = new ValueDto();
- }
- paramDto.setValue(valueDto);
- return valueDto;
- }
-
- private static ParamDto newParamDto(final String parameterName, final ValueType parameterType) {
- final ParamDto argDto = new ParamDto();
- argDto.setParameterName(parameterName);
- argDto.setParameterType(parameterType);
- return argDto;
- }
-
- //endregion
-
- //region > addReturnValue, addReturnReference
- public static boolean addReturnValue(
- final ActionInvocationMementoDto aim,
- final Class<?> returnType,
- final Object returnVal) {
- final ValueDto valueDto = returnValueDtoFor(aim);
- return setValue(valueDto, returnType, returnVal);
- }
-
- public static void addReturnReference(
- final ActionInvocationMementoDto aim,
- final Bookmark bookmark) {
- final ValueDto valueDto = returnValueDtoFor(aim);
- OidDto argValue = asOidDto(bookmark);
- valueDto.setReference(argValue);
- }
-
- //endregion
-
-
-
-
- //region > getNumberOfParameters, getParameters, getParameterNames, getParameterTypes
- public static int getNumberOfParameters(final ActionInvocationMementoDto aim) {
- final ActionInvocationMementoDto.Payload.Parameters params = getParametersHolderElseThrow(aim);
- if(params == null) {
- return 0;
- }
- return params.getNum();
- }
- public static List<ParamDto> getParameters(final ActionInvocationMementoDto aim) {
- final ActionInvocationMementoDto.Payload.Parameters params = getParametersHolderElseThrow(aim);
- final int parameterNumber = getNumberOfParameters(aim);
- final List<ParamDto> paramDtos = Lists.newArrayList();
- for (int i = 0; i < parameterNumber; i++) {
- final ParamDto paramDto = params.getParam().get(i);
- paramDtos.add(paramDto);
- }
- return Collections.unmodifiableList(paramDtos);
- }
- public static List<String> getParameterNames(final ActionInvocationMementoDto aim) {
- return immutableList(Iterables.transform(getParameters(aim), PARAM_DTO_TO_NAME));
- }
- public static List<ValueType> getParameterTypes(final ActionInvocationMementoDto aim) {
- return immutableList(Iterables.transform(getParameters(aim), PARAM_DTO_TO_TYPE));
- }
- //endregion
-
- //region > getParameter, getParameterName, getParameterType
- public static ParamDto getParameter(final ActionInvocationMementoDto aim, final int paramNum) {
- final int parameterNumber = getNumberOfParameters(aim);
- if(paramNum > parameterNumber) {
- throw new IllegalArgumentException(String.format("No such parameter %d (the memento has %d parameters)", paramNum, parameterNumber));
- }
- final List<ParamDto> parameters = getParameters(aim);
- return parameters.get(paramNum);
- }
-
- public static ValueDto getParameterValue(final ActionInvocationMementoDto aim, final int paramNum) {
- final ParamDto paramDto = getParameter(aim, paramNum);
- return valueDtoFor(paramDto);
- }
-
-
- public static String getParameterName(final ActionInvocationMementoDto aim, final int paramNum) {
- return PARAM_DTO_TO_NAME.apply(getParameter(aim, paramNum));
- }
- public static ValueType getParameterType(final ActionInvocationMementoDto aim, final int paramNum) {
- return PARAM_DTO_TO_TYPE.apply(getParameter(aim, paramNum));
- }
- public static boolean isNull(final ActionInvocationMementoDto aim, int paramNum) {
- final ParamDto paramDto = getParameter(aim, paramNum);
- return paramDto.isNull();
- }
- //endregion
-
- //region > getArg
- public static <T> T getArg(final ActionInvocationMementoDto aim, int paramNum, Class<T> cls) {
- final ParamDto paramDto = getParameter(aim, paramNum);
- if(paramDto.isNull()) {
- return null;
- }
- final ValueDto valueDto = valueDtoFor(paramDto);
- switch(paramDto.getParameterType()) {
- case STRING:
- return (T) valueDto.getString();
- case BYTE:
- return (T) valueDto.getByte();
- case SHORT:
- return (T) valueDto.getShort();
- case INT:
- return (T) valueDto.getInt();
- case LONG:
- return (T) valueDto.getLong();
- case FLOAT:
- return (T) valueDto.getFloat();
- case DOUBLE:
- return (T) valueDto.getDouble();
- case BOOLEAN:
- return (T) valueDto.isBoolean();
- case CHAR:
- final String aChar = valueDto.getChar();
- if(Strings.isNullOrEmpty(aChar)) { return null; }
- return (T) (Object)aChar.charAt(0);
- case BIG_DECIMAL:
- return (T) valueDto.getBigDecimal();
- case BIG_INTEGER:
- return (T) valueDto.getBigInteger();
- case JODA_DATE_TIME:
- return (T) JodaDateTimeXMLGregorianCalendarAdapter.parse(valueDto.getDateTime());
- case JODA_LOCAL_DATE:
- return (T) JodaLocalDateXMLGregorianCalendarAdapter.parse(valueDto.getLocalDate());
- case JODA_LOCAL_DATE_TIME:
- return (T) JodaLocalDateTimeXMLGregorianCalendarAdapter.parse(valueDto.getLocalDateTime());
- case JODA_LOCAL_TIME:
- return (T) JodaLocalTimeXMLGregorianCalendarAdapter.parse(valueDto.getLocalTime());
- case REFERENCE:
- return (T) valueDto.getReference();
- }
- throw new IllegalStateException("Parameter type was not recognised (possible bug)");
- }
- //endregion
-
- //region > marshalling
- public static ActionInvocationMementoDto fromXml(Reader reader) {
- Unmarshaller un = null;
- try {
- un = getJaxbContext().createUnmarshaller();
- return (ActionInvocationMementoDto) un.unmarshal(reader);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static ActionInvocationMementoDto fromXml(
- final Class<?> contextClass,
- final String resourceName,
- final Charset charset) throws IOException {
- final URL url = Resources.getResource(contextClass, resourceName);
- final String s = Resources.toString(url, charset);
- return fromXml(new StringReader(s));
- }
-
- public static String toXml(final ActionInvocationMementoDto aim) {
- final CharArrayWriter caw = new CharArrayWriter();
- toXml(aim, caw);
- return caw.toString();
- }
-
- public static void toXml(final ActionInvocationMementoDto aim, final Writer writer) {
- Marshaller m = null;
- try {
- m = getJaxbContext().createMarshaller();
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
- m.marshal(aim, writer);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- }
- //endregion
-
- //region > debugging
- public static void dump(final ActionInvocationMementoDto aim, final PrintStream out) throws JAXBException {
- out.println(toXml(aim));
- }
- //endregion
-
- //region > helpers
- private static void addParamNum(final ActionInvocationMementoDto.Payload.Parameters params, final ParamDto arg) {
- params.getParam().add(arg);
- Integer num = params.getNum();
- if(num == null) {
- num = 0;
- }
- params.setNum(num +1);
- }
-
- private static ActionInvocationMementoDto.Payload.Parameters getParametersHolderElseThrow(final ActionInvocationMementoDto aim) {
- final ActionInvocationMementoDto.Payload payload = getPayloadElseThrow(aim);
- final ActionInvocationMementoDto.Payload.Parameters parameters = payload.getParameters();
- if(parameters == null) {
- throw new IllegalStateException("No parameters have been added");
- }
- return parameters;
- }
-
- private static ActionInvocationMementoDto.Payload.Parameters getParametersHolderAutoCreate(final ActionInvocationMementoDto aim) {
- final ActionInvocationMementoDto.Payload payload = getPayloadAutoCreate(aim);
- ActionInvocationMementoDto.Payload.Parameters params = payload.getParameters();
- if(params == null) {
- params = new ActionInvocationMementoDto.Payload.Parameters();
- payload.setParameters(params);
- }
- return params;
- }
-
- private static ValueDto returnValueDtoFor(final ActionInvocationMementoDto aim) {
- final ActionInvocationMementoDto.Payload payload = getPayloadAutoCreate(aim);
- ValueDto valueDto = payload.getReturn();
- if(valueDto == null) {
- valueDto = new ValueDto();
- payload.setReturn(valueDto);
- }
- return valueDto;
- }
-
- private static ActionInvocationMementoDto.Payload getPayloadAutoCreate(final ActionInvocationMementoDto aim) {
- ActionInvocationMementoDto.Payload payload = aim.getPayload();
- if(payload == null) {
- payload = new ActionInvocationMementoDto.Payload();
- aim.setPayload(payload);
- }
- return payload;
- }
-
- private static ActionInvocationMementoDto.Payload getPayloadElseThrow(final ActionInvocationMementoDto aim) {
- ActionInvocationMementoDto.Payload payload = aim.getPayload();
- if(payload == null) {
- throw new IllegalStateException("No payload has been added");
- }
- return payload;
- }
-
- private static <T> List<T> immutableList(final Iterable<T> transform) {
- return Collections.unmodifiableList(
- Lists.newArrayList(
- transform
- )
- );
- }
-
-
- private static boolean setValue(final ValueDto valueDto, final Class<?> type, final Object returnVal) {
- if(type == String.class) {
- final String argValue = (String) returnVal;
- valueDto.setString(argValue);
- } else
- if(type == byte.class || type == Byte.class) {
- final Byte argValue = (Byte) returnVal;
- valueDto.setByte(argValue);
- } else
- if(type == short.class || type == Short.class) {
- final Short argValue = (Short) returnVal;
- valueDto.setShort(argValue);
- }else
- if(type == int.class || type == Integer.class) {
- final Integer argValue = (Integer) returnVal;
- valueDto.setInt(argValue);
- }else
- if(type == long.class || type == Long.class) {
- final Long argValue = (Long) returnVal;
- valueDto.setLong(argValue);
- }else
- if(type == char.class || type == Character.class) {
- final Character argValue = (Character) returnVal;
- valueDto.setChar("" + argValue);
- }else
- if(type == boolean.class || type == Boolean.class) {
- final Boolean argValue = (Boolean) returnVal;
- valueDto.setBoolean(argValue);
- }else
- if(type == float.class || type == Float.class) {
- final Float argValue = (Float) returnVal;
- valueDto.setFloat(argValue);
- }else
- if(type == double.class || type == Double.class) {
- final Double argValue = (Double) returnVal;
- valueDto.setDouble(argValue);
- }else
- if(type == BigInteger.class) {
- final BigInteger argValue = (BigInteger) returnVal;
- valueDto.setBigInteger(argValue);
- }else
- if(type == BigDecimal.class) {
- final BigDecimal argValue = (BigDecimal) returnVal;
- valueDto.setBigDecimal(argValue);
- }else
- if(type == DateTime.class) {
- final DateTime argValue = (DateTime) returnVal;
- valueDto.setDateTime(JodaDateTimeXMLGregorianCalendarAdapter.print(argValue));
- }else
- if(type == LocalDateTime.class) {
- final LocalDateTime argValue = (LocalDateTime) returnVal;
- valueDto.setLocalDateTime(JodaLocalDateTimeXMLGregorianCalendarAdapter.print(argValue));
- }else
- if(type == LocalDate.class) {
- final LocalDate argValue = (LocalDate) returnVal;
- valueDto.setLocalDate(JodaLocalDateXMLGregorianCalendarAdapter.print(argValue));
- }else
- if(type == LocalTime.class) {
- final LocalTime argValue = (LocalTime) returnVal;
- valueDto.setLocalTime(JodaLocalTimeXMLGregorianCalendarAdapter.print(argValue));
- }else
- {
- // none of the supported value types
- return false;
- }
- return true;
- }
-
- //endregion
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/4967495f/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
----------------------------------------------------------------------
diff --git a/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
deleted file mode 100644
index e88576a..0000000
--- a/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.schema.utils.jaxbadapters;
-
-import javax.inject.Inject;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-
-import org.apache.isis.applib.services.bookmark.Bookmark;
-import org.apache.isis.applib.services.bookmark.BookmarkService;
-import org.apache.isis.applib.services.bookmark.BookmarkService2;
-import org.apache.isis.schema.common.v1.BookmarkObjectState;
-import org.apache.isis.schema.common.v1.OidDto;
-
-public class PersistentEntityAdapter extends XmlAdapter<OidDto, Object> {
-
- @Override
- public Object unmarshal(final OidDto oidDto) throws Exception {
-
- final String objectType = oidDto.getObjectType();
- final String identifier = oidDto.getObjectIdentifier();
- final Bookmark bookmark = new Bookmark(objectType, identifier);
-
- return bookmarkService.lookup(bookmark, BookmarkService2.FieldResetPolicy.DONT_RESET);
- }
-
- @Override
- public OidDto marshal(final Object domainObject) throws Exception {
- if(domainObject == null) {
- return null;
- }
- final Bookmark bookmark = getBookmarkService().bookmarkFor(domainObject);
- final OidDto oidDto = new OidDto();
- oidDto.setObjectIdentifier(bookmark.getIdentifier());
- oidDto.setObjectState(convert(bookmark.getObjectState()));
- oidDto.setObjectType(bookmark.getObjectType());
- return oidDto;
- }
-
- private BookmarkObjectState convert(final Bookmark.ObjectState objectState) {
- switch (objectState) {
- case VIEW_MODEL:return BookmarkObjectState.VIEW_MODEL;
- case TRANSIENT:return BookmarkObjectState.TRANSIENT;
- case PERSISTENT:return BookmarkObjectState.PERSISTENT;
- }
- throw new IllegalArgumentException("Not recognized: " + objectState.name());
- }
-
- protected BookmarkService getBookmarkService() {
- return bookmarkService;
- }
-
- @Inject
- BookmarkService2 bookmarkService;
-}