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 2012/12/06 12:09:57 UTC
[32/51] [partial] ISIS-188: moving components into correct
directories.
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java
new file mode 100644
index 0000000..cb42293
--- /dev/null
+++ b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java
@@ -0,0 +1,559 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.data.xml;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.commons.xml.ContentWriter;
+import org.apache.isis.core.commons.xml.XmlFile;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.CollectionData;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.Data;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.DataManager;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.ListOfRootOid;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.ObjectData;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.ObjectDataVector;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.PersistorException;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.version.FileVersion;
+import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectNotFoundException;
+import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectPersistenceException;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+
+public class XmlDataManager implements DataManager {
+ private final XmlFile xmlFile;
+
+ public XmlDataManager(final XmlFile xmlFile) {
+ this.xmlFile = xmlFile;
+ }
+
+ // ////////////////////////////////////////////////////////
+ // shutdown
+ // ////////////////////////////////////////////////////////
+
+ @Override
+ public void shutdown() {
+ }
+
+ // ////////////////////////////////////////////////////////
+ // SAX Handlers
+ // ////////////////////////////////////////////////////////
+
+ // TODO the following methods are being called repeatedly - is there no
+ // caching? See the print statements
+ private class DataHandler extends DefaultHandler {
+
+ final StringBuilder data = new StringBuilder();
+ CollectionData collection;
+ String fieldName;
+ ObjectData object;
+
+ @Override
+ public void characters(final char[] ch, final int start, final int end) throws SAXException {
+ data.append(new String(ch, start, end));
+ }
+
+ @Override
+ public void endElement(final String ns, final String name, final String tagName) throws SAXException {
+ if (object != null) {
+ if (tagName.equals("value")) {
+ final String value = data.toString();
+ object.set(fieldName, value);
+ }
+ }
+ }
+
+ @Override
+ public void startElement(final String ns, final String name, final String tagName, final Attributes attributes) throws SAXException {
+ if (object != null) {
+ if (tagName.equals("value")) {
+ fieldName = attributes.getValue("field");
+ data.setLength(0);
+ } else if (tagName.equals("association")) {
+ object.set(attributes.getValue("field"), oidFrom(attributes));
+ } else if (tagName.equals("element")) {
+ object.addElement(fieldName, oidFrom(attributes));
+ } else if (tagName.equals("multiple-association")) {
+ fieldName = attributes.getValue("field");
+ object.initCollection(fieldName);
+ }
+ } else if (collection != null) {
+ if (tagName.equals("element")) {
+
+ collection.addElement(oidFrom(attributes));
+ }
+ } else {
+ if (tagName.equals("isis")) {
+ final RootOidDefault oid = oidFrom(attributes);
+ final Version fileVersion = fileVersionFrom(attributes);
+
+ object = new ObjectData(oid, fileVersion);
+ } else if (tagName.equals("collection")) {
+
+ final RootOidDefault oid = oidFrom(attributes);
+ final Version fileVersion = fileVersionFrom(attributes);
+
+ collection = new CollectionData(oid, fileVersion);
+ } else {
+ throw new SAXException("Invalid data");
+ }
+ }
+ }
+ }
+
+ private static RootOidDefault oidFrom(final Attributes attributes) {
+ final String oid = attributes.getValue("oid");
+ return RootOidDefault.deString(oid, getOidMarshaller());
+ }
+
+ private static Version fileVersionFrom(final Attributes attributes) {
+ final String user = attributes.getValue("user");
+ final long version = Long.valueOf(attributes.getValue("ver"), 16).longValue();
+ final Version fileVersion = FileVersion.create(user, version);
+ return fileVersion;
+ }
+
+
+ private class InstanceHandler extends DefaultHandler {
+ Vector<RootOid> instances = new Vector<RootOid>();
+
+ @Override
+ public void characters(final char[] arg0, final int arg1, final int arg2) throws SAXException {
+ }
+
+ @Override
+ public void startElement(final String ns, final String name, final String tagName, final Attributes attrs) throws SAXException {
+ if (tagName.equals("instance")) {
+
+ final String oidStr = attrs.getValue("oid");
+ final RootOidDefault oid = RootOidDefault.deString(oidStr, getOidMarshaller());
+
+ instances.addElement(oid);
+ }
+ }
+ }
+
+ private class NumberHandler extends DefaultHandler {
+ boolean captureValue = false;
+ long value = 0;
+
+ @Override
+ public void characters(final char[] arg0, final int arg1, final int arg2) throws SAXException {
+ if (captureValue) {
+ final String string = new String(arg0, arg1, arg2);
+ value = Long.valueOf(string, 16).longValue();
+ }
+ }
+
+ @Override
+ public void startElement(final String ns, final String name, final String tagName, final Attributes attrs) throws SAXException {
+ captureValue = tagName.equals("number");
+ }
+
+ public ContentWriter writer(final long nextId) {
+ return new ContentWriter() {
+ @Override
+ public void write(final Writer writer) throws IOException {
+ writer.write("<number>");
+ final String nextIdHex = Long.toString(nextId, 16);
+ writer.append("" + nextIdHex);
+ writer.append("</number>");
+ writer.flush();
+ }
+ };
+ }
+
+
+ }
+
+ // ////////////////////////////////////////////////////////
+ // fixtures
+ // ////////////////////////////////////////////////////////
+
+ @Override
+ public boolean isFixturesInstalled() {
+ return xmlFile.isFixturesInstalled();
+ }
+
+ // ////////////////////////////////////////////////////////
+ // loadData
+ // ////////////////////////////////////////////////////////
+
+ @Override
+ public Data loadData(final RootOid oid) {
+ final DataHandler handler = new DataHandler();
+ xmlFile.parse(handler, filename(oid));
+
+ if (handler.object != null) {
+ return handler.object;
+ } else {
+ return handler.collection;
+ }
+ }
+
+ // ////////////////////////////////////////////////////////
+ // getInstances, numberOfInstances
+ // ////////////////////////////////////////////////////////
+
+ @Override
+ public ObjectDataVector getInstances(final ObjectData pattern) {
+
+ final Vector<RootOid> instances = loadInstances(pattern.getSpecification(getSpecificationLoader()));
+
+ if (instances == null) {
+ return new ObjectDataVector();
+ }
+
+ final ObjectDataVector matches = new ObjectDataVector();
+ for (final RootOid oid : instances) {
+ final ObjectData instanceData = (ObjectData) loadData(oid);
+ // TODO check loader first
+ if (instanceData == null) {
+ throw new IsisException("No data found for " + oid + " (possible missing file)");
+ }
+ if (matchesPattern(pattern, instanceData)) {
+ matches.addElement(instanceData);
+ }
+ }
+ return matches;
+ }
+
+ @Override
+ public int numberOfInstances(final ObjectData pattern) {
+ return getInstances(pattern).size();
+ }
+
+ private Vector<RootOid> loadInstances(final ObjectSpecification noSpec) {
+ final InstanceHandler handler = new InstanceHandler();
+ parseSpecAndSubclasses(handler, noSpec);
+ return handler.instances;
+ }
+
+ private void parseSpecAndSubclasses(final InstanceHandler handler, final ObjectSpecification noSpec) {
+ parseIfNotAbstract(noSpec, handler);
+ for (final ObjectSpecification subSpec : noSpec.subclasses()) {
+ parseSpecAndSubclasses(handler, subSpec);
+ }
+ }
+
+ private void parseIfNotAbstract(final ObjectSpecification noSpec, final InstanceHandler handler) {
+ if (noSpec.isAbstract()) {
+ return;
+ }
+ xmlFile.parse(handler, noSpec.getFullIdentifier());
+ }
+
+ /**
+ * A helper that determines if two sets of data match. A match occurs when
+ * the types are the same and any field in the pattern also occurs in the
+ * data set under test.
+ */
+ // TODO we need to be able to find collection instances as well
+ protected boolean matchesPattern(final ObjectData patternData, final ObjectData candidateData) {
+ if (patternData == null || candidateData == null) {
+ throw new NullPointerException("Can't match on nulls " + patternData + " " + candidateData);
+ }
+
+ if (!candidateData.getSpecification(getSpecificationLoader()).isOfType(patternData.getSpecification(getSpecificationLoader()))) {
+ return false;
+ }
+
+ for (final String field : patternData.fields()) {
+ final Object patternFieldValue = patternData.get(field);
+ final Object candidateFieldValue = candidateData.get(field);
+
+ if (candidateFieldValue instanceof ListOfRootOid) {
+ final ListOfRootOid patternElements = (ListOfRootOid) patternFieldValue;
+ for (int i = 0; i < patternElements.size(); i++) {
+ final RootOid requiredElement = patternElements.elementAt(i); // must have this element
+ boolean requiredFound = false;
+ final ListOfRootOid testElements = ((ListOfRootOid) candidateFieldValue);
+ for (int j = 0; j < testElements.size(); j++) {
+ if (requiredElement.equals(testElements.elementAt(j))) {
+ requiredFound = true;
+ break;
+ }
+ }
+ if (!requiredFound) {
+ return false;
+ }
+ }
+ } else {
+ if (!patternFieldValue.equals(candidateFieldValue)) {
+ return false;
+ }
+ }
+
+ }
+
+ return true;
+ }
+
+ /**
+ * Read in the next unique number for the object identifier.
+ */
+ protected long nextId() throws PersistorException {
+ final NumberHandler handler = new NumberHandler();
+ xmlFile.parse(handler, "oid");
+
+ final long nextId = handler.value + 1;
+ xmlFile.writeXml("oid", handler.writer(nextId));
+
+ return nextId;
+ }
+
+ // ////////////////////////////////////////////////////////
+ // insertObject, remove
+ // ////////////////////////////////////////////////////////
+
+ /**
+ * Save the data for an object and adds the reference to a list of instances
+ */
+ @Override
+ public final void insertObject(final ObjectData data) {
+ if (data.getRootOid() == null) {
+ throw new IllegalArgumentException("Oid must be non-null");
+ }
+
+ writeInstanceToItsDataFile(data);
+ final ObjectSpecification objSpec = data.getSpecification(getSpecificationLoader());
+ addReferenceToInstancesFile(data.getRootOid(), objSpec);
+ }
+
+ private void addReferenceToInstancesFile(final RootOid oid, final ObjectSpecification noSpec) {
+ final Vector<RootOid> instances = loadInstances(noSpec);
+ instances.addElement(oid);
+ writeInstanceFile(noSpec, instances);
+ }
+
+ // ////////////////////////////////////////////////////////
+ // remove
+ // ////////////////////////////////////////////////////////
+
+ @Override
+ public final void remove(final RootOid oid) throws ObjectNotFoundException, ObjectPersistenceException {
+ final Data data = loadData(oid);
+ removeReferenceFromInstancesFile(oid, data.getSpecification(getSpecificationLoader()));
+ deleteData(oid);
+ }
+
+ /**
+ * Delete the data for an existing instance.
+ */
+ private void deleteData(final RootOid oid) {
+ xmlFile.delete(filename(oid));
+ }
+
+ private void removeReferenceFromInstancesFile(final RootOid oid, final ObjectSpecification noSpec) {
+ final Vector<RootOid> instances = loadInstances(noSpec);
+ instances.removeElement(oid);
+ writeInstanceFile(noSpec, instances);
+ }
+
+ // ////////////////////////////////////////////////////////
+ // helpers (used by both add & remove)
+ // ////////////////////////////////////////////////////////
+
+ private void writeInstanceFile(final ObjectSpecification noSpec, final Vector<RootOid> instances) {
+ writeInstanceFile(noSpec.getFullIdentifier(), instances);
+ }
+
+ private void writeInstanceFile(final String name, final Vector<RootOid> instances) {
+ xmlFile.writeXml(name, new ContentWriter() {
+ @Override
+ public void write(final Writer writer) throws IOException {
+ writer.write("<instances");
+ Utils.appendAttribute(writer, "name", name);
+ writer.append(">\n");
+
+ for (final RootOid elementAt : instances) {
+ writer.append(" <instance");
+ Utils.appendAttribute(writer, "oid", elementAt.enString(getOidMarshaller()));
+ writer.append("/>\n");
+ }
+ writer.append("</instances>");
+ writer.flush();
+ }
+ });
+ }
+
+ // ////////////////////////////////////////////////////////
+ // save
+ // ////////////////////////////////////////////////////////
+
+ /**
+ * Save the data for latter retrieval.
+ */
+ @Override
+ public final void save(final Data data) {
+ writeInstanceToItsDataFile(data);
+ }
+
+ private void writeInstanceToItsDataFile(final Data data) {
+ xmlFile.writeXml(filename(data.getRootOid()), new ContentWriter() {
+ @Override
+ public void write(final Writer writer) throws IOException {
+ final boolean isObject = data instanceof ObjectData;
+ final String tag = isObject ? "isis" : "collection";
+ writer.write("<");
+ writer.write(tag);
+ final RootOid oid = data.getRootOid();
+ Utils.appendAttribute(writer, "oid", oid.enString(getOidMarshaller()));
+ Utils.appendAttribute(writer, "user", "" + getAuthenticationSession().getUserName());
+
+ final long sequence = data.getVersion().getSequence();
+ final String sequenceString = Long.toHexString(sequence).toUpperCase();
+ Utils.appendAttribute(writer, "ver", "" + sequenceString);
+
+ writer.append(">\n");
+
+ if (isObject) {
+ writeObject(data, writer);
+ } else {
+ writeCollection(data, writer);
+ }
+
+ writer.append("</" + tag + ">\n");
+ writer.flush();
+ }
+
+ });
+ }
+
+ private void writeObject(final Data data, final Writer writer) throws IOException {
+ final ObjectData object = (ObjectData) data;
+ for (final String field : object.fields()) {
+ writeField(writer, object, field);
+ }
+ }
+
+ private void writeField(final Writer writer, final ObjectData object, final String field) throws IOException {
+ final Object entry = object.get(field);
+
+ if (entry instanceof RootOidDefault) {
+ writeAssociationField(writer, field, entry);
+ } else if (entry instanceof ListOfRootOid) {
+ writeMultipleAssociationField(writer, field, entry);
+ } else {
+ writeValueField(writer, field, entry);
+ }
+ }
+
+ private void writeAssociationField(final Writer writer, final String field, final Object entry) throws IOException {
+ final Oid rootOidDefault = (Oid)entry;
+ Assert.assertFalse(rootOidDefault.isTransient());
+ writer.append(" <association");
+ Utils.appendAttribute(writer, "field", field);
+ Utils.appendAttribute(writer, "oid", rootOidDefault.enString(getOidMarshaller()));
+ writer.append("/>\n");
+ }
+
+ private void writeMultipleAssociationField(final Writer writer, final String field, final Object entry) throws IOException {
+ final ListOfRootOid references = (ListOfRootOid) entry;
+ final int size = references.size();
+
+ if (size > 0) {
+ writer.append(" <multiple-association field=\"" + field + "\" ");
+ writer.append(">\n");
+ for (int i = 0; i < size; i++) {
+ final Object oid = references.elementAt(i);
+ final RootOidDefault rootOidDefault = (RootOidDefault) oid;
+ if (rootOidDefault.isTransient()) {
+ throw new ObjectPersistenceException("Can't add tranisent OID (" + oid + ") to " + field + " element.");
+ }
+ writer.append(" <element ");
+ Utils.appendAttribute(writer, "oid", rootOidDefault.enString(getOidMarshaller()));
+ writer.append("/>\n");
+ }
+ writer.append(" </multiple-association>\n");
+ writer.flush();
+ }
+ }
+
+ private static void writeValueField(final Writer writer, final String field, final Object entry) throws IOException {
+ writer.append(" <value");
+ Utils.appendAttribute(writer, "field", field);
+ writer.append(">");
+ writer.append(XmlFile.getValueWithSpecialsEscaped(entry.toString()));
+ writer.append("</value>\n");
+ }
+
+ private static void writeCollection(final Data data, final Writer writer) throws IOException {
+ final CollectionData collection = (CollectionData) data;
+ final ListOfRootOid refs = collection.references();
+ for (int i = 0; i < refs.size(); i++) {
+ final Object oid = refs.elementAt(i);
+ writer.append(" <element");
+ final RootOid rootOid = (RootOid) oid;
+ Utils.appendAttribute(writer, "oid", rootOid.enString(getOidMarshaller()));
+ writer.append("/>\n");
+ }
+ }
+
+
+ private static String filename(final RootOid oid) {
+ return oid.getObjectSpecId() + File.separator + oid.getIdentifier();
+ }
+
+
+
+ // ////////////////////////////////////////////////////////
+ // Debugging
+ // ////////////////////////////////////////////////////////
+
+ @Override
+ public String getDebugData() {
+ return "Data directory " + xmlFile.getDirectory();
+ }
+
+
+ // ////////////////////////////////////////////////////////
+ // dependencies (from context)
+ // ////////////////////////////////////////////////////////
+
+ protected static OidMarshaller getOidMarshaller() {
+ return IsisContext.getOidMarshaller();
+ }
+
+ protected AuthenticationSession getAuthenticationSession() {
+ return IsisContext.getAuthenticationSession();
+ }
+
+ protected SpecificationLoaderSpi getSpecificationLoader() {
+ return IsisContext.getSpecificationLoader();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.java b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.java
new file mode 100644
index 0000000..a9fa71d
--- /dev/null
+++ b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.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.runtimes.dflt.objectstores.xml.internal.services;
+
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+
+public interface ServiceManager {
+
+ void loadServices();
+
+ void registerService(RootOid rootOid);
+
+ RootOid getOidForService(ObjectSpecId objectSpecId);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java
new file mode 100644
index 0000000..9741bdd
--- /dev/null
+++ b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java
@@ -0,0 +1,152 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.services.xml;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.commons.xml.ContentWriter;
+import org.apache.isis.core.commons.xml.XmlFile;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.xml.Utils;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.services.ServiceManager;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+
+
+public class XmlServiceManager implements ServiceManager {
+ private static final String SERVICES_FILE_NAME = "services";
+ private List<ServiceElement> services;
+ private final XmlFile xmlFile;
+
+ public XmlServiceManager(final XmlFile xmlFile) {
+ this.xmlFile = xmlFile;
+ }
+
+ @Override
+ public RootOid getOidForService(final ObjectSpecId objectSpecId) {
+ for (final ServiceElement element: services) {
+ if (element.oid.getObjectSpecId().equals(objectSpecId)) {
+ return element.oid;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void loadServices() {
+ final ServiceHandler handler = new ServiceHandler();
+ xmlFile.parse(handler, SERVICES_FILE_NAME);
+ services = handler.services;
+ }
+
+ @Override
+ public void registerService(final RootOid rootOid) {
+ final RootOidDefault soid = (RootOidDefault) rootOid;
+ final ServiceElement element = new ServiceElement(soid);
+ services.add(element);
+ saveServices();
+ }
+
+ public final void saveServices() {
+ xmlFile.writeXml(SERVICES_FILE_NAME, new ContentWriter() {
+ @Override
+ public void write(final Writer writer) throws IOException {
+ final String tag = SERVICES_FILE_NAME;
+ writer.append("<" + tag + ">\n");
+ for (final ServiceElement element: services) {
+ writer.append(" <service");
+// Utils.appendAttribute(writer, "type", element.oid.getObjectSpecId());
+// Utils.appendAttribute(writer, "id", element.oid.getIdentifier());
+
+ Utils.appendAttribute(writer, "oid", element.oid.enString(getOidMarshaller()));
+
+ writer.append("/>\n");
+ }
+ writer.append("</" + tag + ">\n");
+ }
+ });
+ }
+
+
+ ////////////////////////////////////////////////////
+ // dependencies (from context)
+ ////////////////////////////////////////////////////
+
+ protected OidMarshaller getOidMarshaller() {
+ return IsisContext.getOidMarshaller();
+ }
+}
+
+class ServiceElement {
+ final RootOid oid;
+
+ public ServiceElement(final RootOid oid) {
+ Assert.assertNotNull("oid", oid.enString(getOidMarshaller()));
+ this.oid = oid;
+ }
+
+
+ /////////////////////////////////////////////////////
+ // dependencies (from context)
+ /////////////////////////////////////////////////////
+
+ protected OidMarshaller getOidMarshaller() {
+ return IsisContext.getOidMarshaller();
+ }
+
+}
+
+class ServiceHandler extends DefaultHandler {
+ List<ServiceElement> services = Lists.newArrayList();
+
+ @Override
+ public void startElement(final String ns, final String name, final String tagName, final Attributes attrs) throws SAXException {
+ if (tagName.equals("service")) {
+// final String objectType = attrs.getValue("type");
+// final String identifier = attrs.getValue("id");
+// final RootOid rootOid = RootOidDefault.create(objectType, identifier);
+
+ final String oidStr = attrs.getValue("oid");
+ RootOid rootOid = getOidMarshaller().unmarshal(oidStr, RootOid.class);
+ final ServiceElement service = new ServiceElement(rootOid);
+ services.add(service);
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////
+ // dependencies (from context)
+ ///////////////////////////////////////////////////////
+
+ protected OidMarshaller getOidMarshaller() {
+ return IsisContext.getOidMarshaller();
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java
new file mode 100644
index 0000000..ab52c7d
--- /dev/null
+++ b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java
@@ -0,0 +1,87 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.utils;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.isis.core.commons.exceptions.IsisException;
+
+public class CopyXmlObjectStore {
+ public static void main(final String[] args) {
+ final String workingDirectory = args[0];
+ final String testDirectory = args[1];
+
+ copyAllFiles(testDirectory, workingDirectory);
+ }
+
+ private static void copyAllFiles(final String testDirectory, final String workingDirectory) {
+ final File from = new File(testDirectory);
+ final File to = new File(workingDirectory);
+
+ if (!to.exists()) {
+ to.mkdirs();
+ }
+ if (to.isFile()) {
+ throw new IsisException("To directory is actually a file " + to.getAbsolutePath());
+ }
+
+ final String list[] = from.list();
+ for (final String element : list) {
+ copyFile(new File(from, element), new File(to, element));
+ }
+ }
+
+ private static void copyFile(final File from, final File to) {
+ BufferedInputStream bis = null;
+ BufferedOutputStream bos = null;
+ try {
+ bis = new BufferedInputStream(new FileInputStream(from));
+ bos = new BufferedOutputStream(new FileOutputStream(to));
+
+ final byte buffer[] = new byte[2048];
+
+ int len = 0;
+ while ((len = bis.read(buffer)) > 0) {
+ bos.write(buffer, 0, len);
+ }
+ } catch (final IOException e) {
+ throw new IsisException("Error copying file " + from.getAbsolutePath() + " to " + to.getAbsolutePath(), e);
+ } finally {
+ if (bis != null) {
+ try {
+ bis.close();
+ } catch (final IOException ignore) {
+ }
+ }
+ if (bos != null) {
+ try {
+ bos.close();
+ } catch (final IOException ignore) {
+ }
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java
new file mode 100644
index 0000000..fae21be
--- /dev/null
+++ b/framework/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java
@@ -0,0 +1,40 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.version;
+
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.clock.Clock;
+
+public class FileVersion {
+
+ private static Clock clock;
+ public static void setClock(final Clock clock) {
+ FileVersion.clock = clock;
+ }
+
+ public static Version create(String user) {
+ return create(user, clock.getTime());
+ }
+
+ public static Version create(final String user, final long time) {
+ return Version.create(time, user, time);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/site/apt/index.apt b/framework/objectstore/xml/src/site/apt/index.apt
new file mode 100644
index 0000000..a9f5d57
--- /dev/null
+++ b/framework/objectstore/xml/src/site/apt/index.apt
@@ -0,0 +1,36 @@
+~~ 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.
+
+
+
+XML ObjectStore
+
+ The <xml> object store provides a simple way to persist domain objects to file storage. The format of this file is a
+ proprietary XML schema.
+
+ Note that the XML object store is suitable for single-user standalone apps, but is not intended for multi-user deployments.
+
+Alternatives
+
+ Alternatives include:
+
+ * the {{{../dflt/index.html}dflt}} in-memory object store (for prototyping only)
+
+ * the {{{../sql/index.html}SQL}} object store
+
+ * the {{{../nosql/index.html}NoSQL}} object store
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/site/apt/jottings.apt b/framework/objectstore/xml/src/site/apt/jottings.apt
new file mode 100644
index 0000000..c5d1200
--- /dev/null
+++ b/framework/objectstore/xml/src/site/apt/jottings.apt
@@ -0,0 +1,24 @@
+~~ 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.
+
+
+
+Jottings
+
+ This page is to capture any random jottings relating to this module prior
+ to being moved into formal documentation.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/site/site.xml
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/site/site.xml b/framework/objectstore/xml/src/site/site.xml
new file mode 100644
index 0000000..15eb7eb
--- /dev/null
+++ b/framework/objectstore/xml/src/site/site.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+
+ <body>
+ <breadcrumbs>
+ <item name="XML" href="index.html"/>
+ </breadcrumbs>
+
+ <menu name="XML Objectstore">
+ <item name="About" href="index.html" />
+ <item name="Jottings" href="jottings.html" />
+ </menu>
+
+ <menu name="Objectstore Modules">
+ <item name="Default (in-mem)" href="../dflt/index.html" />
+ <item name="XML" href="../xml/index.html" />
+ <item name="SQL" href="../sql/index.html" />
+ <item name="NoSQL" href="../nosql/index.html" />
+ </menu>
+
+ <menu name="Documentation">
+ <item name="${docbkxGuideTitle} (PDF)" href="docbkx/pdf/${docbkxGuideName}.pdf" />
+ <item name="${docbkxGuideTitle} (HTML)" href="docbkx/html/guide/${docbkxGuideName}.html" />
+ </menu>
+
+ <menu name="Maven Reports" ref="reports" />
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_isFixturesInstalled.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_isFixturesInstalled.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_isFixturesInstalled.java
new file mode 100644
index 0000000..8738c54
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_isFixturesInstalled.java
@@ -0,0 +1,56 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml;
+
+import static org.junit.Assert.assertFalse;
+
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+
+public class XmlObjectStoreTest_isFixturesInstalled {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Mock
+ private IsisConfiguration mockConfiguration;
+
+ private XmlObjectStore objectStore;
+
+ @Before
+ public void setUp() throws Exception {
+ context.ignoring(mockConfiguration);
+ objectStore = new XmlObjectStore(mockConfiguration);
+ }
+
+
+ @Test
+ public void validateObjectStoreCreation_isFixturesInstalled() throws Exception {
+ assertFalse(objectStore.isFixturesInstalled());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_name.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_name.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_name.java
new file mode 100644
index 0000000..ca260b3
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_name.java
@@ -0,0 +1,62 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+
+public class XmlObjectStoreTest_name {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Mock
+ private IsisConfiguration mockConfiguration;
+
+ private XmlObjectStore objectStore;
+
+ @Before
+ public void setUp() throws Exception {
+ context.ignoring(mockConfiguration);
+ objectStore = new XmlObjectStore(mockConfiguration);
+ }
+
+ @Test
+ public void name() throws Exception {
+ assertTrue(objectStore.name().equals("XML"));
+ }
+
+
+ @Test
+ public void validateObjectStoreCreation_isFixturesInstalled() throws Exception {
+ assertFalse(objectStore.isFixturesInstalled());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_persist.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_persist.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_persist.java
new file mode 100644
index 0000000..46f86b7
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_persist.java
@@ -0,0 +1,55 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import org.apache.isis.core.testsupport.files.Files;
+import org.apache.isis.core.testsupport.files.Files.Recursion;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.testsupport.tck.ObjectStoreContractTest_persist;
+
+public class XmlObjectStoreTest_persist extends ObjectStoreContractTest_persist {
+
+ @Override
+ protected PersistenceMechanismInstaller createPersistenceMechanismInstaller() {
+ return new XmlPersistenceMechanismInstaller();
+ }
+
+ protected void resetPersistenceStore() {
+ Files.deleteFiles("xml/objects", Files.and(endsWithXml(), notServicesXml()), Recursion.DO_RECURSE);
+ }
+
+ private static FilenameFilter notServicesXml() {
+ return new FilenameFilter() {
+
+ @Override
+ public boolean accept(File parentDirectory, String fileName) {
+ return !fileName.equals("services.xml");
+ }
+ };
+ }
+
+ private static FilenameFilter endsWithXml() {
+ return Files.filterFileNameExtension(".xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_toRefactor.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_toRefactor.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_toRefactor.java
new file mode 100644
index 0000000..f818aa3
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlObjectStoreTest_toRefactor.java
@@ -0,0 +1,173 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.clock.DefaultClock;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryBuiltIn;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+
+public class XmlObjectStoreTest_toRefactor {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().with(new XmlPersistenceMechanismInstaller()).build();
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private XmlObjectStore objectStore;
+
+ @Mock
+ private PersistenceQueryBuiltIn persistenceHelper;
+
+ private PersistenceCommandContext transaction;
+
+ ObjectAdapter mockAdapter;
+
+ private ObjectAdapter adapter1;
+
+ private ObjectSpecification specification;
+
+
+ @Before
+ public void setUpSystem() throws Exception {
+
+ // system
+ objectStore = iswf.getObjectStore(XmlObjectStore.class);
+ objectStore.setClock(new DefaultClock());
+
+ // objects
+// adapter.setOptimisticLock(new SerialNumberVersion(23, null, null));
+// adapter.setupOid(RootOidDefault.createPersistent(objectType, ""+1));
+
+ transaction = null;
+ }
+
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void createSaveObjectCommand_setsVersionOnAdapter() throws Exception {
+
+ allowingGetOidAndGetObjectAndTitleStringFromAdapter();
+ context.checking(new Expectations() {
+ {
+ one(mockAdapter).setVersion(with(any(Version.class)));
+ }
+ });
+ objectStore.createSaveObjectCommand(mockAdapter);
+ }
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void createCreateObjectCommand_andExecute_persistsNewInstance() throws Exception {
+ // given
+ final CreateObjectCommand command = objectStore.createCreateObjectCommand(adapter1);
+ // when
+ command.execute(transaction);
+ // then
+ assertFalse(objectStore.hasInstances(specification));
+ }
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void validatesDestroyObjectCommand() throws Exception {
+ final DestroyObjectCommand command = objectStore.createDestroyObjectCommand(adapter1);
+ command.execute(transaction);
+ assertFalse(objectStore.hasInstances(specification));
+ }
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void validatesSaveObjectCommand() throws Exception {
+ final SaveObjectCommand command = objectStore.createSaveObjectCommand(adapter1);
+ command.execute(transaction);
+ assertTrue(objectStore.hasInstances(specification));
+ }
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void validatesGettingObjectStoreInstances() throws Exception {
+ final SaveObjectCommand command = objectStore.createSaveObjectCommand(adapter1);
+ objectStore.execute(Collections.<PersistenceCommand> singletonList(command));
+ final List<ObjectAdapter> array = objectStore.loadInstancesAndAdapt(persistenceHelper);
+ assertTrue(array.size() == 1);
+ }
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void validatesObjectStoreHasInstances() throws Exception {
+ final SaveObjectCommand command = objectStore.createSaveObjectCommand(adapter1);
+ objectStore.execute(Collections.<PersistenceCommand> singletonList(command));
+ assertTrue(objectStore.hasInstances(specification));
+ }
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void validatesObjectStoreIfFixtureIsInstalled() throws Exception {
+ final SaveObjectCommand command = objectStore.createSaveObjectCommand(adapter1);
+ objectStore.execute(Collections.<PersistenceCommand> singletonList(command));
+ objectStore.open();
+ assertTrue(objectStore.isFixturesInstalled());
+ }
+
+ @Ignore // DKH: refactor to use contract tests (see in-memory object store for basis)
+ @Test
+ public void validatesObjectStoreGetObject() throws Exception {
+ final SaveObjectCommand command = objectStore.createSaveObjectCommand(adapter1);
+ objectStore.execute(Collections.<PersistenceCommand> singletonList(command));
+ final ObjectAdapter retrievedAdapter = objectStore.loadInstanceAndAdapt((TypedOid) adapter1.getOid());
+ assertTrue(retrievedAdapter.getOid().equals(adapter1.getOid()));
+ }
+
+
+ private void allowingGetOidAndGetObjectAndTitleStringFromAdapter() {
+ context.checking(new Expectations() {
+ {
+ allowing(mockAdapter).getOid();
+ allowing(mockAdapter).getObject();
+ allowing(mockAdapter).titleString();
+ }
+ });
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlPersistenceMechanismInstallerTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlPersistenceMechanismInstallerTest.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlPersistenceMechanismInstallerTest.java
new file mode 100644
index 0000000..63a906c
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/XmlPersistenceMechanismInstallerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml;
+
+import static org.junit.Assert.assertTrue;
+
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionFactory;
+
+public class XmlPersistenceMechanismInstallerTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+
+ private DeploymentType deploymentType;
+ XmlPersistenceMechanismInstaller installer;
+
+ @Mock
+ private IsisConfiguration mockConfiguration;
+
+ @Before
+ public void setUpSystem() throws Exception {
+ installer = new XmlPersistenceMechanismInstaller();
+ installer.setConfiguration(mockConfiguration);
+ }
+
+ @Test
+ public void testCreatePersistenceSessionFactory() throws Exception {
+ deploymentType = DeploymentType.EXPLORATION;
+ final PersistenceSessionFactory factory = installer.createPersistenceSessionFactory(deploymentType);
+ assertTrue(factory != null);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/DefaultClockTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/DefaultClockTest.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/DefaultClockTest.java
new file mode 100644
index 0000000..88d8f93
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/DefaultClockTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.clock;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+
+public class DefaultClockTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private DefaultClock clock;
+
+
+ @Test
+ public void testGetTime() {
+ clock = new DefaultClock();
+ assertTrue(clock.getTime() > 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/TestClock.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/TestClock.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/TestClock.java
new file mode 100644
index 0000000..714346a
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/clock/TestClock.java
@@ -0,0 +1,30 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.clock;
+
+public class TestClock implements Clock {
+ long time = 0;
+
+ @Override
+ public synchronized long getTime() {
+ time += 1;
+ return time;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataTest.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataTest.java
new file mode 100644
index 0000000..5841437
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.data;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.testspec.ObjectSpecificationStub;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.clock.DefaultClock;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.version.FileVersion;
+
+public class ObjectDataTest extends TestCase {
+
+ private String objectType = "CLK";
+
+ public void testValueField() {
+ FileVersion.setClock(new DefaultClock());
+
+ final ObjectSpecificationStub type = new ObjectSpecificationStub("test");
+ final ObjectData objectData = new ObjectData(RootOidDefault.create(ObjectSpecId.of(objectType), ""+13), FileVersion.create(""));
+
+ assertEquals(null, objectData.get("name"));
+ objectData.set("name", "value");
+ assertEquals("value", objectData.get("name"));
+
+ final Iterator<String> e = objectData.fields().iterator();
+ e.next();
+ assertFalse(e.hasNext());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVectorTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVectorTest.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVectorTest.java
new file mode 100644
index 0000000..1d1adf2
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVectorTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.runtimes.dflt.objectstores.xml.internal.data;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.adapter.oid.Oid.State;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.testspec.ObjectSpecificationStub;
+import org.apache.isis.runtimes.dflt.objectstores.xml.internal.version.FileVersion;
+
+public class ObjectDataVectorTest {
+
+ private final String objectType = "ODV";
+
+ private ObjectDataVector objectDataVector;
+ private ObjectData objectData;
+ private ObjectSpecificationStub spec;
+ private RootOidDefault oid;
+ private Version version;
+
+ @Before
+ public void setUp() throws Exception {
+ final ObjectSpecId objectSpecId = ObjectSpecId.of(objectType);
+ oid = new RootOidDefault(objectSpecId, ""+1, State.TRANSIENT);
+
+ spec = new ObjectSpecificationStub(this.getClass());
+ spec.fields = Collections.emptyList();
+
+ version = FileVersion.create("", System.currentTimeMillis());
+ objectData = new ObjectData(oid, version);
+ objectDataVector = new ObjectDataVector();
+ }
+
+ @Test
+ public void validatesObjectDataIsStored() throws Exception {
+ objectDataVector.addElement(objectData);
+ assertTrue(objectDataVector.contains(objectData));
+ assertTrue(objectDataVector.element(0).equals(objectData));
+ }
+
+ @Test
+ public void validatesObjectDataVectorSize() throws Exception {
+ objectDataVector.addElement(objectData);
+ assertTrue(objectDataVector.size() == 1);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ReferenceVectorTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ReferenceVectorTest.java b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ReferenceVectorTest.java
new file mode 100644
index 0000000..7b06036
--- /dev/null
+++ b/framework/objectstore/xml/src/test/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ReferenceVectorTest.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.runtimes.dflt.objectstores.xml.internal.data;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+
+public class ReferenceVectorTest {
+
+ private final String objectType = "FOO";
+
+ private ListOfRootOid listOfRootOid;
+ private RootOidDefault oid;
+
+ @Before
+ public void setUp() throws Exception {
+ oid = RootOidDefault.createTransient(ObjectSpecId.of(objectType), ""+1);
+ listOfRootOid = new ListOfRootOid();
+ }
+
+ @Test
+ public void validatesSerialOidIsStoredInElements() throws Exception {
+ listOfRootOid.add(oid);
+ assertTrue(listOfRootOid.elementAt(0).equals(oid));
+ }
+
+ @Test
+ public void validatesSerialOidIsRemovedInElements() throws Exception {
+ listOfRootOid.add(oid);
+ listOfRootOid.remove(oid);
+ assertTrue(listOfRootOid.size() == 0);
+ }
+
+ @Test
+ public void validatesReferenceVectorIsEqual() throws Exception {
+ assertTrue(listOfRootOid.equals(listOfRootOid));
+ assertTrue(listOfRootOid.equals(new ListOfRootOid()));
+ assertFalse(listOfRootOid.equals(new Object()));
+ }
+
+ @Test
+ public void validateReferenceVectorHashCode() throws Exception {
+ assertTrue(listOfRootOid.hashCode() == 630);
+ }
+
+ @Test
+ public void validateReferenceToString() throws Exception {
+ assertTrue(listOfRootOid.toString() != null);
+ }
+
+}