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/13 01:01:07 UTC
[35/52] [partial] ISIS-188: renaming packages in line with
groupId:artifactId
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ListOfRootOid.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ListOfRootOid.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ListOfRootOid.java
deleted file mode 100644
index 1e7cd3c..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ListOfRootOid.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.xml.internal.data;
-
-import java.util.List;
-
-import com.google.common.collect.Lists;
-
-import org.apache.isis.core.commons.lang.ToString;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-
-public class ListOfRootOid {
-
- private final List<RootOid> elements = Lists.newArrayList();
-
- public void add(final RootOid oid) {
- elements.add(oid);
- }
-
- public void remove(final RootOid oid) {
- elements.remove(oid);
- }
-
- public int size() {
- return elements.size();
- }
-
- public RootOid elementAt(final int index) {
- return elements.get(index);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (obj == this) {
- return true;
- }
-
- if (obj instanceof ListOfRootOid) {
- return ((ListOfRootOid) obj).elements.equals(elements);
- }
-
- return false;
- }
-
- @Override
- public int hashCode() {
- int h = 17;
- h = 37 * h + elements.hashCode();
- return h;
- }
-
- @Override
- public String toString() {
- final ToString str = new ToString(this);
- str.append("refs", elements);
- return str.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectData.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectData.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectData.java
deleted file mode 100644
index 179ca2d..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectData.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.xml.internal.data;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-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.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacetUtils;
-import org.apache.isis.runtimes.dflt.objectstores.xml.internal.version.FileVersion;
-
-/**
- * A logical collection of elements of a specified type
- */
-public class ObjectData extends Data {
- private final Map<String, Object> fieldById;
-
- public ObjectData(final RootOid oid, final Version version) {
- super(oid, version);
- fieldById = new HashMap<String, Object>();
- }
-
- public Iterable<String> fields() {
- return fieldById.keySet();
- }
-
- // ////////////////////////////////////////////////////////
- // id
- // ////////////////////////////////////////////////////////
-
- public String id(final String fieldId) {
- final Object field = get(fieldId);
- return field == null ? null : "" + ((RootOidDefault) field).getIdentifier();
- }
-
- // ////////////////////////////////////////////////////////
- // value
- // ////////////////////////////////////////////////////////
-
- public void set(final String fieldId, final String value) {
- fieldById.put(fieldId, value);
- }
-
- public void saveValue(final String fieldId, final boolean isEmpty, final String encodedString) {
- if (isEmpty) {
- fieldById.remove(fieldId);
- } else {
- fieldById.put(fieldId, encodedString);
- }
- }
-
- public String value(final String fieldId) {
- return (String) get(fieldId);
- }
-
- // ////////////////////////////////////////////////////////
- // reference
- // ////////////////////////////////////////////////////////
-
- public Object get(final String fieldId) {
- return fieldById.get(fieldId);
- }
-
- public void set(final String fieldId, final Object oid) {
- if (oid == null) {
- fieldById.remove(fieldId);
- } else {
- fieldById.put(fieldId, oid);
- }
- }
-
- // ////////////////////////////////////////////////////////
- // collection
- // ////////////////////////////////////////////////////////
-
- public void initCollection(final String fieldId) {
- fieldById.put(fieldId, new ListOfRootOid());
- }
-
- public void addElement(final String fieldId, final RootOidDefault elementOid) {
- if (!fieldById.containsKey(fieldId)) {
- throw new IsisException("Field " + fieldId + " not found in hashtable");
- }
-
- final ListOfRootOid v = (ListOfRootOid) fieldById.get(fieldId);
- v.add(elementOid);
- }
-
- public ListOfRootOid elements(final String fieldId) {
- return (ListOfRootOid) fieldById.get(fieldId);
- }
-
- public void addAssociation(final ObjectAdapter fieldContent, final String fieldId, final boolean ensurePersistent) {
- final boolean notAlreadyPersistent = fieldContent != null && fieldContent.isTransient();
- if (ensurePersistent && notAlreadyPersistent) {
- throw new IllegalStateException("Cannot save an object that is not persistent: " + fieldContent);
- }
- // LOG.debug("adding reference field " + fieldId +" " + fieldContent);
- set(fieldId, fieldContent == null ? null : fieldContent.getOid());
- }
-
- public void addInternalCollection(final ObjectAdapter collection, final String fieldId, final boolean ensurePersistent) {
- /*
- * if (ensurePersistent && collection != null && collection.getOid() ==
- * null) { throw new
- * IllegalStateException("Cannot save a collection that is not persistent: "
- * + collection); }
- */
-
- initCollection(fieldId);
-
- // int size = collection.size();
-
- final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(collection);
- for (final ObjectAdapter element : facet.iterable(collection)) {
- // LOG.debug("adding element to internal collection field " +
- // fieldId +" " + element);
- final Object elementOid = element.getOid();
- if (elementOid == null) {
- throw new IllegalStateException("Element is not persistent " + element);
- }
-
- addElement(fieldId, (RootOidDefault) elementOid);
- }
- }
-
- // ////////////////////////////////////////////////////////
- // toString
- // ////////////////////////////////////////////////////////
-
- @Override
- public String toString() {
- return "ObjectData[type=" + getObjectSpecId() + ",oid=" + getRootOid() + ",fields=" + fieldById + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVector.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVector.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVector.java
deleted file mode 100644
index 00189b4..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/ObjectDataVector.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.xml.internal.data;
-
-import java.util.Vector;
-
-public class ObjectDataVector {
- Vector elements = new Vector();
-
- public void addElement(final ObjectData instanceData) {
- elements.addElement(instanceData);
- }
-
- public int size() {
- return elements.size();
- }
-
- public ObjectData element(final int i) {
- return (ObjectData) elements.elementAt(i);
- }
-
- public boolean contains(final ObjectData data) {
- return elements.contains(data);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/PersistorException.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/PersistorException.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/PersistorException.java
deleted file mode 100644
index 77e1bf3..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/PersistorException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.xml.internal.data;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-
-public class PersistorException extends IsisException {
- private static final long serialVersionUID = 1L;
-
- public PersistorException() {
- super();
- }
-
- public PersistorException(final String message) {
- super(message);
- }
-
- public PersistorException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- public PersistorException(final Throwable cause) {
- super(cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/Utils.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/Utils.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/Utils.java
deleted file mode 100644
index 28e7d93..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/Utils.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.xml.internal.data.xml;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import org.apache.isis.core.commons.config.ConfigurationConstants;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-
-public class Utils {
-
- private Utils(){}
-
- public static final String ENCODING_PROPERTY = ConfigurationConstants.ROOT + "xmlos.encoding";
- public static final String DEFAULT_ENCODING = "ISO-8859-1";
-
- public static String lookupCharset(final IsisConfiguration configuration) {
- return configuration.getString(ENCODING_PROPERTY, DEFAULT_ENCODING);
- }
-
- public static String attribute(final String name, final String value) {
- return appendAttribute(new StringBuilder(), name, value).toString();
- }
-
- public static StringBuilder appendAttribute(StringBuilder buf, final String name, final String value) {
- return buf.append(" ").append(name).append("=\"").append(value).append("\"");
- }
-
- public static Writer appendAttribute(Writer buf, final String name, final String value) throws IOException {
- buf.append(" ");
- buf.append(name);
- buf.append("=\"");
- buf.append(value);
- buf.append("\"");
- return buf;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java
deleted file mode 100644
index cb42293..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/data/xml/XmlDataManager.java
+++ /dev/null
@@ -1,559 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.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/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.java
deleted file mode 100644
index a9fa71d..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/ServiceManager.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.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/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java
deleted file mode 100644
index 9741bdd..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/services/xml/XmlServiceManager.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.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/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java
deleted file mode 100644
index ab52c7d..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/utils/CopyXmlObjectStore.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.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/951a0fe4/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java b/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java
deleted file mode 100644
index fae21be..0000000
--- a/component/objectstore/xml/src/main/java/org/apache/isis/runtimes/dflt/objectstores/xml/internal/version/FileVersion.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_isFixturesInstalled.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_isFixturesInstalled.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_isFixturesInstalled.java
new file mode 100644
index 0000000..8a58492
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_isFixturesInstalled.java
@@ -0,0 +1,57 @@
+/*
+ * 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.objectstore.xml;
+
+import static org.junit.Assert.assertFalse;
+
+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.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.xml.XmlObjectStore;
+
+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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_name.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_name.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_name.java
new file mode 100644
index 0000000..1b7267c
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_name.java
@@ -0,0 +1,63 @@
+/*
+ * 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.objectstore.xml;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+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.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.xml.XmlObjectStore;
+
+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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_persist.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_persist.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_persist.java
new file mode 100644
index 0000000..9011fd3
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_persist.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.objectstore.xml;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import org.apache.isis.core.integtestsupport.tck.ObjectStoreContractTest_persist;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.core.unittestsupport.files.Files;
+import org.apache.isis.core.unittestsupport.files.Files.Recursion;
+import org.apache.isis.objectstore.xml.XmlPersistenceMechanismInstaller;
+
+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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_toRefactor.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_toRefactor.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_toRefactor.java
new file mode 100644
index 0000000..b798ff5
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlObjectStoreTest_toRefactor.java
@@ -0,0 +1,175 @@
+/*
+ * 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.objectstore.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.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+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.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryBuiltIn;
+import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.xml.XmlObjectStore;
+import org.apache.isis.objectstore.xml.XmlPersistenceMechanismInstaller;
+import org.apache.isis.objectstore.xml.internal.clock.DefaultClock;
+
+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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlPersistenceMechanismInstallerTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlPersistenceMechanismInstallerTest.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlPersistenceMechanismInstallerTest.java
new file mode 100644
index 0000000..504a133
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/XmlPersistenceMechanismInstallerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.objectstore.xml;
+
+import static org.junit.Assert.assertTrue;
+
+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.runtime.system.DeploymentType;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
+import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.xml.XmlPersistenceMechanismInstaller;
+
+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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/DefaultClockTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/DefaultClockTest.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/DefaultClockTest.java
new file mode 100644
index 0000000..16e121f
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/DefaultClockTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.objectstore.xml.internal.clock;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.xml.internal.clock.DefaultClock;
+
+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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/TestClock.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/TestClock.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/TestClock.java
new file mode 100644
index 0000000..c7cf58c
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/clock/TestClock.java
@@ -0,0 +1,32 @@
+/*
+ * 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.objectstore.xml.internal.clock;
+
+import org.apache.isis.objectstore.xml.internal.clock.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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataTest.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataTest.java
new file mode 100644
index 0000000..40585f7
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.objectstore.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.objectstore.xml.internal.clock.DefaultClock;
+import org.apache.isis.objectstore.xml.internal.data.ObjectData;
+import org.apache.isis.objectstore.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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataVectorTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataVectorTest.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataVectorTest.java
new file mode 100644
index 0000000..152cd48
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ObjectDataVectorTest.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.objectstore.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.objectstore.xml.internal.data.ObjectData;
+import org.apache.isis.objectstore.xml.internal.data.ObjectDataVector;
+import org.apache.isis.objectstore.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/951a0fe4/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ReferenceVectorTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ReferenceVectorTest.java b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ReferenceVectorTest.java
new file mode 100644
index 0000000..e202feb
--- /dev/null
+++ b/component/objectstore/xml/src/test/java/org/apache/isis/objectstore/xml/internal/data/ReferenceVectorTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.objectstore.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;
+import org.apache.isis.objectstore.xml.internal.data.ListOfRootOid;
+
+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);
+ }
+
+}