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 2015/11/13 18:57:14 UTC
[03/11] isis git commit: ISIS-1250: take-on of the JaxbService...
ISIS-1250: take-on of the JaxbService...
... providing toXml() and toXsd(), along with supporting mixins.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/b5994367
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/b5994367
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/b5994367
Branch: refs/heads/master
Commit: b59943674b6029eb9d5c52172a3d3e79ed35a60a
Parents: 01aeb77
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Nov 12 23:26:39 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Nov 12 23:26:39 2015 +0000
----------------------------------------------------------------------
.../apache/isis/applib/services/jaxb/Dto.java | 21 ++++
.../applib/services/jaxb/Dto_downloadXml.java | 70 ++++++++++++
.../applib/services/jaxb/Dto_downloadXsd.java | 112 +++++++++++++++++++
.../isis/applib/services/jaxb/JaxbService.java | 31 +++++
.../apache/isis/applib/services/jaxb/Util.java | 33 ++++++
core/runtime/pom.xml | 5 +
.../services/jaxb/JaxbServiceDefault.java | 83 ++++++++++++++
.../util/CatalogingSchemaOutputResolver.java | 74 ++++++++++++
.../jaxb/util/PersistentEntityAdapter.java | 51 +++++++++
.../jaxb/util/StreamResultWithWriter.java | 45 ++++++++
.../persistence/spi/JdoObjectIdSerializer.java | 2 +-
11 files changed, 526 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java
new file mode 100644
index 0000000..84a6999
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java
@@ -0,0 +1,21 @@
+/**
+ * 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.applib.services.jaxb;
+
+public interface Dto {
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
new file mode 100644
index 0000000..91332b3
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
@@ -0,0 +1,70 @@
+/**
+ * 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.applib.services.jaxb;
+
+import java.io.IOException;
+
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+import javax.inject.Inject;
+import javax.xml.bind.JAXBException;
+
+import org.apache.isis.applib.FatalException;
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.MemberOrder;
+import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.value.Clob;
+
+@Mixin
+public class Dto_downloadXml {
+
+ private final Dto dto;
+
+ final MimeType mimeTypeApplicationZip;
+
+ public Dto_downloadXml(final Dto dto) {
+ this.dto = dto;
+ try {
+ mimeTypeApplicationZip = new MimeType("application", "zip");
+ } catch (final MimeTypeParseException ex) {
+ throw new FatalException(ex);
+ }
+ }
+
+ public static class ActionDomainEvent extends org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
+
+ @Action(
+ domainEvent = ActionDomainEvent.class,
+ semantics = SemanticsOf.SAFE
+ )
+ @MemberOrder(sequence = "500.1")
+ public Object $$(final String fileName) throws JAXBException, IOException {
+
+ final String xml = jaxbService.toXml(dto);
+ return new Clob(Util.withSuffix(fileName, "xml"), "text/xml", xml);
+ }
+
+ public String default0$$() {
+ return Util.withSuffix(dto.getClass().getName(), "xml");
+ }
+
+
+ @Inject
+ JaxbService jaxbService;
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
new file mode 100644
index 0000000..ce10bb1
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
@@ -0,0 +1,112 @@
+/**
+ * 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.applib.services.jaxb;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+import javax.inject.Inject;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.FatalException;
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.MemberOrder;
+import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.value.Blob;
+import org.apache.isis.applib.value.Clob;
+
+@Mixin
+public class Dto_downloadXsd {
+
+ private final Dto dto;
+
+ final MimeType mimeTypeApplicationZip;
+
+ public Dto_downloadXsd(final Dto dto) {
+ this.dto = dto;
+ try {
+ mimeTypeApplicationZip = new MimeType("application", "zip");
+ } catch (final MimeTypeParseException ex) {
+ throw new FatalException(ex);
+ }
+ }
+
+ public static class ActionDomainEvent extends org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
+
+ @Action(
+ domainEvent = ActionDomainEvent.class,
+ semantics = SemanticsOf.SAFE
+ )
+ @MemberOrder(sequence = "500.2")
+ public Object $$(final String fileName) {
+
+ final Map<String, String> map = jaxbService.toXsd(dto);
+
+ if(map.isEmpty()) {
+ container.warnUser("No schemas were generated for " + dto.getClass().getName() + "; programming error?");
+ return null;
+ }
+
+ if(map.size() == 1) {
+ final Map.Entry<String, String> entry = map.entrySet().iterator().next();
+ return new Clob(Util.withSuffix(fileName, "xsd"), "text/xml", entry.getValue());
+ }
+
+ try {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final ZipOutputStream zos = new ZipOutputStream(baos);
+ final OutputStreamWriter writer = new OutputStreamWriter(zos);
+
+ for (Map.Entry<String, String> entry : map.entrySet()) {
+ final String namespaceUri = entry.getKey();
+ final String schemaText = entry.getValue();
+ zos.putNextEntry(new ZipEntry(zipEntryNameFor(namespaceUri)));
+ writer.write(schemaText);
+ writer.flush();
+ zos.closeEntry();
+ }
+
+ writer.close();
+ return new Blob(Util.withSuffix(fileName, "zip"), mimeTypeApplicationZip, baos.toByteArray());
+ } catch (final IOException ex) {
+ throw new FatalException("Unable to create zip", ex);
+ }
+ }
+
+ public String default0$$() {
+ return Util.withSuffix(dto.getClass().getName(), "xsd");
+ }
+
+ private static String zipEntryNameFor(final String namespaceUri) {
+ return Util.withSuffix(namespaceUri, "xsd");
+ }
+
+
+ @Inject
+ DomainObjectContainer container;
+
+ @Inject
+ JaxbService jaxbService;
+}
+
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
new file mode 100644
index 0000000..61c0ecb
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
@@ -0,0 +1,31 @@
+/**
+ * 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.applib.services.jaxb;
+
+import java.util.Map;
+
+import org.apache.isis.applib.annotation.Programmatic;
+
+public interface JaxbService {
+
+ @Programmatic
+ public String toXml(final Dto dto);
+
+ @Programmatic
+ public Map<String, String> toXsd(final Dto dto);
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java
new file mode 100644
index 0000000..0859d07
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java
@@ -0,0 +1,33 @@
+/**
+ * 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.applib.services.jaxb;
+
+class Util {
+
+ private Util(){}
+
+ static String withSuffix(String fileName, String suffix) {
+ if(!suffix.startsWith(".")) {
+ suffix = "." + suffix;
+ }
+ if(!fileName.endsWith(suffix)) {
+ fileName += suffix;
+ }
+ return fileName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/pom.xml
----------------------------------------------------------------------
diff --git a/core/runtime/pom.xml b/core/runtime/pom.xml
index c50a2ec..6d41a7f 100644
--- a/core/runtime/pom.xml
+++ b/core/runtime/pom.xml
@@ -105,6 +105,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-schema</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
new file mode 100644
index 0000000..4fd19aa
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
@@ -0,0 +1,83 @@
+/**
+ * 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.core.runtime.services.jaxb;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+import org.apache.isis.applib.ApplicationException;
+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.Dto;
+import org.apache.isis.applib.services.jaxb.JaxbService;
+import org.apache.isis.core.runtime.services.jaxb.util.CatalogingSchemaOutputResolver;
+import org.apache.isis.core.runtime.services.jaxb.util.PersistentEntityAdapter;
+
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
+public class JaxbServiceDefault implements JaxbService {
+
+ public Map<String,String> toXsd(final Dto dto) {
+
+ try {
+ final Class<? extends Dto> dtoClass = dto.getClass();
+ final JAXBContext context = JAXBContext.newInstance(dtoClass);
+
+ final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver();
+ context.generateSchema(outputResolver);
+
+ return outputResolver.asMap();
+ } catch (final JAXBException | IOException ex) {
+ throw new ApplicationException(ex);
+ }
+ }
+
+ public String toXml(final Dto dto) {
+
+ try {
+ final Class<? extends Dto> dtoClass = dto.getClass();
+ final JAXBContext context = JAXBContext.newInstance(dtoClass);
+
+ final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
+ container.injectServicesInto(adapter);
+
+ final Marshaller marshaller = context.createMarshaller();
+ marshaller.setAdapter(PersistentEntityAdapter.class, adapter);
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+
+ final StringWriter sw = new StringWriter();
+ marshaller.marshal(dto, sw);
+ return sw.toString();
+
+ } catch (final JAXBException ex) {
+ throw new ApplicationException(ex);
+ }
+
+ }
+
+ @Inject
+ DomainObjectContainer container;
+}
+
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
new file mode 100644
index 0000000..460c97f
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
@@ -0,0 +1,74 @@
+/**
+ * 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.core.runtime.services.jaxb.util;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.transform.Result;
+import javax.xml.transform.stream.StreamResult;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * An implementation of {@link SchemaOutputResolver} that keeps track of all the schemas for which it has
+ * {@link #createOutput(String, String) created} an output {@link StreamResult} containing the content of the schema.
+ */
+public class CatalogingSchemaOutputResolver extends SchemaOutputResolver
+{
+ private List<String> namespaceUris = Lists.newArrayList();
+
+ public List<String> getNamespaceUris() {
+ return namespaceUris;
+ }
+
+ private Map<String, StreamResultWithWriter> schemaResultByNamespaceUri = Maps.newLinkedHashMap();
+
+ public String getSchemaTextFor(final String namespaceUri) {
+ final StreamResultWithWriter streamResult = schemaResultByNamespaceUri.get(namespaceUri);
+ return streamResult != null? streamResult.asString(): null;
+ }
+
+ @Override
+ public Result createOutput(
+ final String namespaceUri, final String suggestedFileName) throws IOException {
+
+ final StreamResultWithWriter result = new StreamResultWithWriter();
+
+ result.setSystemId(namespaceUri);
+
+ namespaceUris.add(namespaceUri);
+ schemaResultByNamespaceUri.put(namespaceUri, result);
+
+ return result;
+ }
+
+ public Map<String, String> asMap() {
+ final Map<String,String> map = Maps.newLinkedHashMap();
+ final List<String> namespaceUris = getNamespaceUris();
+
+ for (String namespaceUri : namespaceUris) {
+ map.put(namespaceUri, getSchemaTextFor(namespaceUri));
+ }
+
+ return Collections.unmodifiableMap(map);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
new file mode 100644
index 0000000..6987129
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
@@ -0,0 +1,51 @@
+/**
+ * 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.core.runtime.services.jaxb.util;
+
+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.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);
+ }
+
+ @Override
+ public OidDto marshal(final Object domainObject) throws Exception {
+ final Bookmark bookmark = bookmarkService.bookmarkFor(domainObject);
+ final OidDto oidDto = new OidDto();
+ oidDto.setObjectIdentifier(bookmark.getIdentifier());
+ oidDto.setObjectState(BookmarkObjectState.PERSISTENT);
+ oidDto.setObjectType(bookmark.getObjectType());
+ return oidDto;
+ }
+
+ @Inject
+ BookmarkService bookmarkService;
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java
new file mode 100644
index 0000000..99884be
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java
@@ -0,0 +1,45 @@
+/**
+ * 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.core.runtime.services.jaxb.util;
+
+import java.io.StringWriter;
+
+import javax.xml.transform.stream.StreamResult;
+
+/**
+ * A {@link StreamResult} that contains its own writer.
+ *
+ * <p>
+ * The point is that the writer is only ever queried lazily AFTER the result has been generated.
+ * </p>
+ */
+public class StreamResultWithWriter extends StreamResult {
+ private final StringWriter writer;
+
+ public StreamResultWithWriter() {
+ this(new StringWriter());
+ }
+
+ private StreamResultWithWriter(StringWriter writer) {
+ super(writer);
+ this.writer = writer;
+ }
+
+ public String asString() {
+ return writer.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
index ff662eb..1df7289 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
@@ -125,7 +125,7 @@ public final class JdoObjectIdSerializer {
// the JDO spec (5.4.3) requires that OIDs are serializable toString and
// recreatable through the constructor
- return jdoOid.getClass().getName().toString() + SEPARATOR + jdoOid.toString();
+ return jdoOid.getClass().getName() + SEPARATOR + jdoOid.toString();
}
private static List<String> dnPrefixes = Arrays.asList("S", "I", "L", "M", "B");
Re: [03/11] isis git commit: ISIS-1250: take-on of the JaxbService...
Posted by Dan Haywood <da...@haywood-associates.co.uk>.
That might be a copy N paste from the downloadXsd which generates multiple
files, zipped together.
I'll double check.
Thx for the review.
Cheers, Dan.
On 14 Nov 2015 19:21, "Martin Grigorov" <mg...@apache.org> wrote:
> Hi Dan,
>
> On Fri, Nov 13, 2015 at 6:57 PM, <da...@apache.org> wrote:
>
> > public Dto_downloadXml(final Dto dto) {
> > + this.dto = dto;
> > + try {
> > + mimeTypeApplicationZip = new MimeType("application", "zip");
> >
>
> What is the magic here that it is a "zip"?
> The methods below deal with "xml" (as I'd expect).
>
>
> > + } catch (final MimeTypeParseException ex) {
> > + throw new FatalException(ex);
> > + }
> > + }
> > +
> > + public static class ActionDomainEvent extends
> > org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
> > +
> > + @Action(
> > + domainEvent = ActionDomainEvent.class,
> > + semantics = SemanticsOf.SAFE
> > + )
> > + @MemberOrder(sequence = "500.1")
> > + public Object $(final String fileName) throws JAXBException,
> > IOException {
> > +
> > + final String xml = jaxbService.toXml(dto);
> > + return new Clob(Util.withSuffix(fileName, "xml"), "text/xml",
> > xml);
> > + }
> > +
> > + public String default0$() {
> > + return Util.withSuffix(dto.getClass().getName(), "xml");
> > + }
> >
>
>
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
Re: [03/11] isis git commit: ISIS-1250: take-on of the JaxbService...
Posted by Martin Grigorov <mg...@apache.org>.
Hi Dan,
On Fri, Nov 13, 2015 at 6:57 PM, <da...@apache.org> wrote:
> public Dto_downloadXml(final Dto dto) {
> + this.dto = dto;
> + try {
> + mimeTypeApplicationZip = new MimeType("application", "zip");
>
What is the magic here that it is a "zip"?
The methods below deal with "xml" (as I'd expect).
> + } catch (final MimeTypeParseException ex) {
> + throw new FatalException(ex);
> + }
> + }
> +
> + public static class ActionDomainEvent extends
> org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
> +
> + @Action(
> + domainEvent = ActionDomainEvent.class,
> + semantics = SemanticsOf.SAFE
> + )
> + @MemberOrder(sequence = "500.1")
> + public Object $(final String fileName) throws JAXBException,
> IOException {
> +
> + final String xml = jaxbService.toXml(dto);
> + return new Clob(Util.withSuffix(fileName, "xml"), "text/xml",
> xml);
> + }
> +
> + public String default0$() {
> + return Util.withSuffix(dto.getClass().getName(), "xml");
> + }
>
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov