[jboss-svn-commits] JBoss Common SVN: r4455 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat May 29 18:50:45 EDT 2010
Author: ALRubinger
Date: 2010-05-29 18:50:43 -0400 (Sat, 29 May 2010)
New Revision: 4455
Added:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/SerializableView.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializableView.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableViewImpl.java
shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.SerializableView
shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializableView
Removed:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializable.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableImpl.java
shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializable
Modified:
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/SerializationTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableOriginalImpl.java
Log:
[SHRINKWRAP-178] Add a protocol-nonspecific SerializableView interface
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/SerializableView.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/SerializableView.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/SerializableView.java 2010-05-29 22:50:43 UTC (rev 4455)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.shrinkwrap.api.serialization;
+
+import java.io.Serializable;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Assignable;
+
+/**
+ * {@link Serializable} view of an {@link Archive}. This is
+ * the base interface for all {@link Serializable} views of an
+ * {@link Archive}, and may be extended/implementated
+ * to define a custom wire protocol.
+ * <br /><br />
+ * ShrinkWrap will use a {@link ZipSerializableView}
+ * implementation when
+ * assigning archives to this type directly via {@link Assignable#as(Class)}.
+ * However consumers obtaining this type should not assume anything
+ * about the protocol being used under the hood; it may be any subtype.
+ * <br /><br />
+ * May be reassigned back to a normal {@link Archive}
+ * view via {@link Assignable#as(Class)}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface SerializableView extends Assignable, Serializable
+{
+
+}
Deleted: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializable.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializable.java 2010-05-29 01:39:13 UTC (rev 4454)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializable.java 2010-05-29 22:50:43 UTC (rev 4455)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.shrinkwrap.api.serialization;
-
-import java.io.Serializable;
-
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.Assignable;
-
-/**
- * {@link Serializable} view of an {@link Archive} where
- * contents are encoded in ZIP format during
- * Serialization. May be reassigned to a normal {@link Archive}
- * view via {@link Assignable#as(Class)}.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface ZipSerializable extends Serializable, Assignable
-{
-
-}
Copied: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializableView.java (from rev 4454, shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializable.java)
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializableView.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/serialization/ZipSerializableView.java 2010-05-29 22:50:43 UTC (rev 4455)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.shrinkwrap.api.serialization;
+
+import java.io.Serializable;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Assignable;
+
+/**
+ * {@link Serializable} view of an {@link Archive} where
+ * contents are encoded in ZIP format during
+ * Serialization. May be reassigned to a normal {@link Archive}
+ * view via {@link Assignable#as(Class)}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ZipSerializableView extends SerializableView
+{
+
+}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableImpl.java 2010-05-29 01:39:13 UTC (rev 4454)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableImpl.java 2010-05-29 22:50:43 UTC (rev 4455)
@@ -1,234 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.shrinkwrap.impl.base.serialization;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.zip.ZipInputStream;
-
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
-import org.jboss.shrinkwrap.api.importer.ZipImporter;
-import org.jboss.shrinkwrap.api.serialization.ZipSerializable;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.impl.base.AssignableBase;
-import org.jboss.shrinkwrap.impl.base.Validate;
-import org.jboss.shrinkwrap.impl.base.io.IOUtil;
-
-/**
- * Implementation of a {@link Serializable} view of {@link Archive}s,
- * backed by ZIP en/decoding the contents during serialization/deserialization.
- * Defines the wire protocol and must remain backwards-compatible.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ZipSerializableImpl extends AssignableBase implements ZipSerializable
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(ZipSerializableOriginalImpl.class.getName());
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Name of the archive; to be serialized
- */
- private final String name;
-
- /**
- * Underlying archive. Won't be directly serialized;
- * instead we'll encode it as ZIP and send that
- */
- private transient Archive<?> archive;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a new instance, wrapping the specified {@link Archive}
- */
- public ZipSerializableImpl(final Archive<?> archive)
- {
- Validate.notNull(archive, "Archive must be specified");
- final String name = archive.getName();
- Validate.notNullOrEmpty(name, "Name of archive must be specified");
- this.archive = archive;
- this.name = name;
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * {@inheritDoc}
- * @see org.jboss.shrinkwrap.impl.base.AssignableBase#getArchive()
- */
- @Override
- protected Archive<?> getArchive()
- {
- assert archive != null : "Underlying archive may never be null; illegal state";
- return archive;
- }
-
- //-------------------------------------------------------------------------------------||
- // Serialization ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Serializes the invocation with a custom form
- *
- * @serialData After all non-transient fields are written, we
- * send the {@link Archive} contents encoded as ZIP.
- */
- private void writeObject(final ObjectOutputStream out) throws IOException
- {
- // Default write of non-transient fields
- out.defaultWriteObject();
-
- // Write as ZIP
- final InputStream in = archive.as(ZipExporter.class).exportZip();
- try
- {
- IOUtil.copy(in, out); // Don't close the outstream
- }
- finally
- {
- // In case we get an InputStream type that supports closing
- in.close();
- }
-
- // Log
- if (log.isLoggable(Level.FINER))
- {
- log.finer("Wrote archive: " + archive.toString());
- }
- }
-
- /**
- * Deserializes according to the custom form
- * defined by {@link ZipSerializableOriginalImpl#writeObject(ObjectOutputStream)}
- */
- private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- // Get default form
- in.defaultReadObject();
-
- // Create new Archive
- final String name = this.name;
- final ZipImporter archive = ShrinkWrap.create(ZipImporter.class, name);
-
- // Read in archive
- final ZipInputStream remains = new ZipInputStream(new DoNotDelegateCloseInputStream(in));
-
- try
- {
- // Read in
- archive.importZip(remains);
-
- // Set
- this.archive = archive.as(JavaArchive.class);
- }
- finally
- {
- // Close up our stream, but not the underlying ObjectInputStream
- remains.close();
- }
-
- // Log
- if (log.isLoggable(Level.FINER))
- {
- log.finer("Read in archive: " + archive.toString());
- }
-
- /*
- * Leave this bit here.
- *
- * After reading in the ZIP stream contents, we need to also
- * get to the EOF marker (which is not read in by the ZIP import process
- * because it's the ZIP header, not part of the true contents. Putting
- * this loop here ensures we reach the marker, which is *not* the true
- * end of the stream. Object data may be read again after here
- * via something like:
- *
- * in.readObject();
- *
- * Without this loop we'll get an OptionalDataException when trying to
- * read more objects in from the stream. In the future we may add state
- * which needs to be part of the serialization protocol, and things
- * need to stay in order, so they'll be added *after* the archive ZIP contents.
- * Thus we must be able to read them.
- */
- while (in.read() != -1);
-
- }
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Classes ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * A {@link InputStream} which does not delegate the {@link InputStream#close()}
- * operation to the wrapped delegate; we cannot close the {@link ObjectInputStream}
- * passed into {@link ZipSerializableOriginalImpl#readObject(ObjectInputStream)}.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
- private static class DoNotDelegateCloseInputStream extends FilterInputStream
- {
-
- protected DoNotDelegateCloseInputStream(final InputStream in)
- {
- super(in);
- }
-
- /**
- * {@inheritDoc}
- * @see java.io.FilterInputStream#close()
- */
- @Override
- public void close() throws IOException
- {
- // NOOP
- }
-
- }
-
-}
Copied: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableViewImpl.java (from rev 4454, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableImpl.java)
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableViewImpl.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableViewImpl.java 2010-05-29 22:50:43 UTC (rev 4455)
@@ -0,0 +1,234 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.shrinkwrap.impl.base.serialization;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.ZipInputStream;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.importer.ZipImporter;
+import org.jboss.shrinkwrap.api.serialization.ZipSerializableView;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.AssignableBase;
+import org.jboss.shrinkwrap.impl.base.Validate;
+import org.jboss.shrinkwrap.impl.base.io.IOUtil;
+
+/**
+ * Implementation of a {@link Serializable} view of {@link Archive}s,
+ * backed by ZIP en/decoding the contents during serialization/deserialization.
+ * Defines the wire protocol and must remain backwards-compatible.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ZipSerializableViewImpl extends AssignableBase implements ZipSerializableView
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ZipSerializableViewImpl.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Name of the archive; to be serialized
+ */
+ private final String name;
+
+ /**
+ * Underlying archive. Won't be directly serialized;
+ * instead we'll encode it as ZIP and send that
+ */
+ private transient Archive<?> archive;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new instance, wrapping the specified {@link Archive}
+ */
+ public ZipSerializableViewImpl(final Archive<?> archive)
+ {
+ Validate.notNull(archive, "Archive must be specified");
+ final String name = archive.getName();
+ Validate.notNullOrEmpty(name, "Name of archive must be specified");
+ this.archive = archive;
+ this.name = name;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.impl.base.AssignableBase#getArchive()
+ */
+ @Override
+ protected Archive<?> getArchive()
+ {
+ assert archive != null : "Underlying archive may never be null; illegal state";
+ return archive;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Serialization ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Serializes the invocation with a custom form
+ *
+ * @serialData After all non-transient fields are written, we
+ * send the {@link Archive} contents encoded as ZIP.
+ */
+ private void writeObject(final ObjectOutputStream out) throws IOException
+ {
+ // Default write of non-transient fields
+ out.defaultWriteObject();
+
+ // Write as ZIP
+ final InputStream in = archive.as(ZipExporter.class).exportZip();
+ try
+ {
+ IOUtil.copy(in, out); // Don't close the outstream
+ }
+ finally
+ {
+ // In case we get an InputStream type that supports closing
+ in.close();
+ }
+
+ // Log
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer("Wrote archive: " + archive.toString());
+ }
+ }
+
+ /**
+ * Deserializes according to the custom form
+ * defined by {@link ZipSerializableImpl#writeObject(ObjectOutputStream)}
+ */
+ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ // Get default form
+ in.defaultReadObject();
+
+ // Create new Archive
+ final String name = this.name;
+ final ZipImporter archive = ShrinkWrap.create(ZipImporter.class, name);
+
+ // Read in archive
+ final ZipInputStream remains = new ZipInputStream(new DoNotDelegateCloseInputStream(in));
+
+ try
+ {
+ // Read in
+ archive.importZip(remains);
+
+ // Set
+ this.archive = archive.as(JavaArchive.class);
+ }
+ finally
+ {
+ // Close up our stream, but not the underlying ObjectInputStream
+ remains.close();
+ }
+
+ // Log
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer("Read in archive: " + archive.toString());
+ }
+
+ /*
+ * Leave this bit here.
+ *
+ * After reading in the ZIP stream contents, we need to also
+ * get to the EOF marker (which is not read in by the ZIP import process
+ * because it's the ZIP header, not part of the true contents. Putting
+ * this loop here ensures we reach the marker, which is *not* the true
+ * end of the stream. Object data may be read again after here
+ * via something like:
+ *
+ * in.readObject();
+ *
+ * Without this loop we'll get an OptionalDataException when trying to
+ * read more objects in from the stream. In the future we may add state
+ * which needs to be part of the serialization protocol, and things
+ * need to stay in order, so they'll be added *after* the archive ZIP contents.
+ * Thus we must be able to read them.
+ */
+ while (in.read() != -1);
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Classes ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * A {@link InputStream} which does not delegate the {@link InputStream#close()}
+ * operation to the wrapped delegate; we cannot close the {@link ObjectInputStream}
+ * passed into {@link ZipSerializableImpl#readObject(ObjectInputStream)}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ private static class DoNotDelegateCloseInputStream extends FilterInputStream
+ {
+
+ protected DoNotDelegateCloseInputStream(final InputStream in)
+ {
+ super(in);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.io.FilterInputStream#close()
+ */
+ @Override
+ public void close() throws IOException
+ {
+ // NOOP
+ }
+
+ }
+
+}
Added: shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.SerializableView
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.SerializableView (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.SerializableView 2010-05-29 22:50:43 UTC (rev 4455)
@@ -0,0 +1 @@
+org.jboss.shrinkwrap.impl.base.serialization.ZipSerializableViewImpl
\ No newline at end of file
Deleted: shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializable
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializable 2010-05-29 01:39:13 UTC (rev 4454)
+++ shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializable 2010-05-29 22:50:43 UTC (rev 4455)
@@ -1 +0,0 @@
-org.jboss.shrinkwrap.impl.base.serialization.ZipSerializableImpl
\ No newline at end of file
Copied: shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializableView (from rev 4454, shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializable)
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializableView (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.serialization.ZipSerializableView 2010-05-29 22:50:43 UTC (rev 4455)
@@ -0,0 +1 @@
+org.jboss.shrinkwrap.impl.base.serialization.ZipSerializableViewImpl
\ No newline at end of file
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/SerializationTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/SerializationTestCase.java 2010-05-29 01:39:13 UTC (rev 4454)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/SerializationTestCase.java 2010-05-29 22:50:43 UTC (rev 4455)
@@ -36,14 +36,16 @@
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Node;
import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.serialization.ZipSerializable;
+import org.jboss.shrinkwrap.api.serialization.SerializableView;
+import org.jboss.shrinkwrap.api.serialization.ZipSerializableView;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
/**
* Ensures that serialization of Archives is possible via
- * the {@link ZipSerializable} view.
+ * the {@link SerializableView}s.
*
* SHRINKWRAP-178
*
@@ -62,40 +64,88 @@
*/
private static final Logger log = Logger.getLogger(SerializationTestCase.class.getName());
+ /**
+ * Name of the payload archive used in testing serialization
+ */
+ private static final String NAME_PAYLOAD_ARCHIVE = "serializedArchive.jar";
+
//-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * A populated archive to be used in testing serialization
+ */
+ private JavaArchive payload;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a payload archive to be used in serialization tests
+ */
+ @Before
+ public void createPayload()
+ {
+ payload = ShrinkWrap.create(JavaArchive.class, NAME_PAYLOAD_ARCHIVE).addClasses(SerializationTestCase.class,
+ JavaArchive.class);
+ }
+
+ //-------------------------------------------------------------------------------------||
// Tests ------------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
- * Ensures we may serialize an {@link Archive} and preserve contents
- * as expected
+ * Ensures we may serialize an {@link Archive} as {@link ZipSerializableView}
+ * and preserve contents as expected
*/
@Test
- public void serialize() throws Exception
+ public void zipSerializableView() throws Exception
{
+ this.testSerializableView(ZipSerializableView.class);
+ }
+
+ /**
+ * Ensures we may serialize an {@link Archive} as {@link SerializableView}
+ * and preserve contents as expected
+ */
+ @Test
+ public void serializableView() throws Exception
+ {
+ this.testSerializableView(SerializableView.class);
+ }
+
+ /**
+ * Tests that the payload archive may be serialized as the specified {@link SerializableView}
+ * type and contents of the roundtrip are as expected.
+ * @param <S>
+ * @param serializableView
+ * @throws Exception
+ */
+ private <S extends SerializableView> void testSerializableView(final Class<S> serializableView) throws Exception
+ {
// Define the initial archive
- final String name = "serializedArchive.jar";
- final JavaArchive original = ShrinkWrap.create(JavaArchive.class, name).addClasses(SerializationTestCase.class,
- JavaArchive.class);
- log.info("Before: " + original.toString(true));
+ log.info("Before: " + payload.toString(true));
// Serialize
- final JavaArchive roundtrip = serializeAndDeserialize(original.as(ZipSerializable.class)).as(JavaArchive.class);
+ final JavaArchive roundtrip = serializeAndDeserialize(payload.as(serializableView)).as(JavaArchive.class);
log.info("After: " + roundtrip.toString(true));
// Ensure contents are as expected
- final Map<ArchivePath, Node> originalContents = original.getContent();
+ final Map<ArchivePath, Node> originalContents = payload.getContent();
final Map<ArchivePath, Node> roundtripContents = roundtrip.getContent();
Assert.assertEquals("Contents after serialization were not as expected", originalContents, roundtripContents);
- Assert.assertEquals("Name of original archive was not as expected", name, original.getName());
- Assert.assertEquals("Name not as expected after serialization", original.getName(), roundtrip.getName());
+ Assert.assertEquals("Name of original archive was not as expected", NAME_PAYLOAD_ARCHIVE, payload.getName());
+ Assert.assertEquals("Name not as expected after serialization", payload.getName(), roundtrip.getName());
+
}
/**
* Ensures that the current serialization protocol is compatible
* with the version initially released. We accomplish this by mocking
* {@link ZipSerializableOriginalImpl} and redefining its class name via
- * {@link SerializationTestCase#serializeAndDeserialize(ZipSerializable, Class)},
+ * {@link SerializationTestCase#serializeAndDeserialize(ZipSerializableView, Class)},
* which uses the {@link SpoofingObjectOutputStream}.
* @throws Exception
*/
@@ -109,7 +159,7 @@
* Ensures that the original serialization protocol is compatible
* with the current version. We accomplish this by mocking
* {@link ZipSerializableOriginalImpl} and redefining its class name via
- * {@link SerializationTestCase#serializeAndDeserialize(ZipSerializable, Class)},
+ * {@link SerializationTestCase#serializeAndDeserialize(ZipSerializableView, Class)},
* which uses the {@link SpoofingObjectOutputStream}.
* @throws Exception
*/
@@ -138,7 +188,7 @@
* @throws IOException
* @throws ClassNotFoundException
*/
- private static ZipSerializable serializeAndDeserialize(final ZipSerializable archive) throws IOException,
+ private static SerializableView serializeAndDeserialize(final SerializableView archive) throws IOException,
ClassNotFoundException
{
assert archive != null : "Archive must be specified";
@@ -148,7 +198,7 @@
out.flush();
out.close();
final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
- final ZipSerializable roundtrip = (ZipSerializable) in.readObject();
+ final SerializableView roundtrip = (SerializableView) in.readObject();
in.close();
return roundtrip;
}
@@ -157,14 +207,14 @@
* Roundtrip serializes/deserializes the specified {@link Invocation}
* and reconsitutes/redefines as the specified target type
*
- * @param archive The original {@link ZipSerializable} instance
+ * @param archive The original {@link ZipSerializableView} instance
* @param The new type we should cast to after deserialization
* @see http://crazybob.org/2006/01/unit-testing-serialization-evolution.html
* @see http://crazybob.org/2006/01/unit-testing-serialization-evolution_13.html
* @see http://www.theserverside.com/news/thread.tss?thread_id=38398
* @author Bob Lee
*/
- private static <S extends ZipSerializable> S serializeAndDeserialize(final ZipSerializable archive,
+ private static <S extends SerializableView> S serializeAndDeserialize(final SerializableView archive,
final Class<S> targetType) throws IOException
{
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableOriginalImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableOriginalImpl.java 2010-05-29 01:39:13 UTC (rev 4454)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/serialization/ZipSerializableOriginalImpl.java 2010-05-29 22:50:43 UTC (rev 4455)
@@ -29,14 +29,14 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.importer.ZipImporter;
-import org.jboss.shrinkwrap.api.serialization.ZipSerializable;
+import org.jboss.shrinkwrap.api.serialization.ZipSerializableView;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.impl.base.AssignableBase;
import org.jboss.shrinkwrap.impl.base.Validate;
import org.jboss.shrinkwrap.impl.base.io.IOUtil;
/**
- * Copy of {@link ZipSerializableImpl} so we may test for
+ * Copy of {@link ZipSerializableViewImpl} so we may test for
* backwards-compatibility of the wire protocol. This class is
* *never to change* once we publish/lock the wire protocol. It is
* used to mock different ShrinkWrap versions communicating
@@ -45,7 +45,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class ZipSerializableOriginalImpl extends AssignableBase implements ZipSerializable
+public class ZipSerializableOriginalImpl extends AssignableBase implements ZipSerializableView
{
//-------------------------------------------------------------------------------------||
@@ -60,7 +60,7 @@
/**
* Logger
*/
- private static final Logger log = Logger.getLogger(ZipSerializableImpl.class.getName());
+ private static final Logger log = Logger.getLogger(ZipSerializableViewImpl.class.getName());
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
@@ -144,7 +144,7 @@
/**
* Deserializes according to the custom form
- * defined by {@link ZipSerializableImpl#writeObject(ObjectOutputStream)}
+ * defined by {@link ZipSerializableViewImpl#writeObject(ObjectOutputStream)}
*/
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
{
@@ -207,7 +207,7 @@
/**
* A {@link InputStream} which does not delegate the {@link InputStream#close()}
* operation to the wrapped delegate; we cannot close the {@link ObjectInputStream}
- * passed into {@link ZipSerializableImpl#readObject(ObjectInputStream)}.
+ * passed into {@link ZipSerializableViewImpl#readObject(ObjectInputStream)}.
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
More information about the jboss-svn-commits
mailing list