Return-Path: Delivered-To: apmail-incubator-river-commits-archive@minotaur.apache.org Received: (qmail 86553 invoked from network); 15 Apr 2010 01:11:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Apr 2010 01:11:45 -0000 Received: (qmail 80337 invoked by uid 500); 15 Apr 2010 01:11:45 -0000 Delivered-To: apmail-incubator-river-commits-archive@incubator.apache.org Received: (qmail 80319 invoked by uid 500); 15 Apr 2010 01:11:45 -0000 Mailing-List: contact river-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: river-dev@incubator.apache.org Delivered-To: mailing list river-commits@incubator.apache.org Received: (qmail 80312 invoked by uid 99); 15 Apr 2010 01:11:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 01:11:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 01:11:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DA6382388993; Thu, 15 Apr 2010 01:11:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r934258 [1/2] - in /incubator/river/jtsk/trunk: ./ qa/ qa/harness/policy/ src/com/sun/jini/constants/ src/com/sun/jini/norm/ src/com/sun/jini/outrigger/ src/com/sun/jini/phoenix/ src/com/sun/jini/reggie/ src/manifest/ src/net/jini/activatio... Date: Thu, 15 Apr 2010 01:11:13 -0000 To: river-commits@incubator.apache.org From: peter_firmstone@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100415011113.DA6382388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: peter_firmstone Date: Thu Apr 15 01:11:12 2010 New Revision: 934258 URL: http://svn.apache.org/viewvc?rev=934258&view=rev Log: This patch integrates changes to replace the RMIClassLoaderSPI with a CodebaseAccessClassLoader as per River-336. Although it doesn't include all changes to PreferredClassProvider. Additional changes to net.jini.io have been made to allow a subset of this package to be built at a later stage for CDC Personal Profile 1.11 (a subset of Java 1.4.2). An additional interface has been created, which is a subset of ServiceRegistrar, which ServiceRegistrar now extends, this is to enable building a release for CDC Personal Profile 1.11 or greater at a later point in time, without causing any breakage to existing application software. Furthermore additional permissions have been granted to the qa test defaulttest.policy in order for some random test failures to pass. This was specific to the Java 1.6 platform and I believe related to the -source=5 and -target=jsr14 compiler optimisations that load a security manager earlier, it is also related to the removal of the need to utilise the jre/etc directory for jsk-policy.jar These changes are experimental, and some incomplete, please feel free to make comments and reccommendations or hightlite any unforseen issues. The Apache River version has been changed to 2.2.0 Added: incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java (with props) incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java (with props) incubator/river/jtsk/trunk/src/net/jini/io/CDCMarshalledObject.java (with props) incubator/river/jtsk/trunk/src/net/jini/io/Convert.java (with props) incubator/river/jtsk/trunk/src/net/jini/io/FromMOInputStream.java (with props) incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceInputStream.java (with props) incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceOutputStream.java (with props) incubator/river/jtsk/trunk/src/net/jini/io/PackageVersion.java (with props) incubator/river/jtsk/trunk/src/net/jini/io/ToMOInputStream.java (with props) incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessClassLoader.java (with props) incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessOverridePermission.java (with props) incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseClassAccess.java (with props) incubator/river/jtsk/trunk/src/net/jini/loader/RMIClassLoaderCodebaseAccess.java (with props) incubator/river/jtsk/trunk/test/src/net/jini/io/ incubator/river/jtsk/trunk/test/src/net/jini/io/ConvertTest.java (with props) incubator/river/jtsk/trunk/test/src/net/jini/io/PackageVersionTest.java (with props) Modified: incubator/river/jtsk/trunk/ (props changed) incubator/river/jtsk/trunk/common.xml incubator/river/jtsk/trunk/qa/build.xml incubator/river/jtsk/trunk/qa/harness/policy/defaulttest.policy incubator/river/jtsk/trunk/src/com/sun/jini/constants/VersionConstants.java incubator/river/jtsk/trunk/src/com/sun/jini/norm/NormServerBaseImpl.java incubator/river/jtsk/trunk/src/com/sun/jini/outrigger/EntryRep.java incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupImpl.java incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupInit.java incubator/river/jtsk/trunk/src/com/sun/jini/reggie/EntryClassBase.java incubator/river/jtsk/trunk/src/manifest/jsk-platform.mf incubator/river/jtsk/trunk/src/net/jini/activation/ActivationGroup.java incubator/river/jtsk/trunk/src/net/jini/core/lookup/ServiceRegistrar.java incubator/river/jtsk/trunk/src/net/jini/io/MarshalInputStream.java incubator/river/jtsk/trunk/src/net/jini/io/MarshalOutputStream.java incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java incubator/river/jtsk/trunk/src/net/jini/loader/ClassAnnotation.java incubator/river/jtsk/trunk/src/net/jini/loader/ClassLoading.java incubator/river/jtsk/trunk/src/net/jini/loader/DownloadPermission.java incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java incubator/river/jtsk/trunk/src/net/jini/loader/pref/RequireDlPermProvider.java incubator/river/jtsk/trunk/src/net/jini/security/proxytrust/ProxyTrustVerifier.java Propchange: incubator/river/jtsk/trunk/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Thu Apr 15 01:11:12 2010 @@ -1,10 +1,11 @@ classes lib-ext build.properties -deps configentry +deps nbproject -build .* +build +qa_output.txt lib-dl dist Modified: incubator/river/jtsk/trunk/common.xml URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/common.xml?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/common.xml (original) +++ incubator/river/jtsk/trunk/common.xml Thu Apr 15 01:11:12 2010 @@ -25,7 +25,7 @@ - + Modified: incubator/river/jtsk/trunk/qa/build.xml URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/qa/build.xml?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/qa/build.xml (original) +++ incubator/river/jtsk/trunk/qa/build.xml Thu Apr 15 01:11:12 2010 @@ -250,8 +250,9 @@ - + + Modified: incubator/river/jtsk/trunk/qa/harness/policy/defaulttest.policy URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/qa/harness/policy/defaulttest.policy?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/qa/harness/policy/defaulttest.policy (original) +++ incubator/river/jtsk/trunk/qa/harness/policy/defaulttest.policy Thu Apr 15 01:11:12 2010 @@ -1,3 +1,24 @@ +// Grants required for jdk1.6 combined with source=5 and target=jsr14 +// I think this has something to do with the new java 6 Policy implementation, +// the visibility of our policy implementations on the boot classpath and +// jdk1.6 compiler optimisations. See River-334 +grant codebase "file:${com.sun.jini.jsk.home}${/}lib-ext${/}*" { + permission java.security.AllPermission "", ""; + //permission java.security.SecurityPermission "getProperty.net.jini.security.policy.PolicyFileProvider.basePolicyClass"; + //permission java.util.PropertyPermission "java.security.policy", "read"; + //permission java.util.PropertyPermission "java.security.policy", "write"; + //permission java.lang.RuntimePermission "accessClassInPackage.sun.security.provider"; + //permission java.lang.RuntimePermission "getProtectionDomain"; + //permission net.jini.security.GrantPermission "java.security.AllPermission \"\", \"\""; +}; + +// Grants required for jdk1.6 combined with source=5 and target=jsr14 +// I think this has something to do with the new java 6 Policy implementation, +// the visibility of our policy implementations on the boot classpath and +// jdk1.6 compiler optimisations. See River-334 +grant codebase "file:${com.sun.jini.test.home}${/}lib-ext${/}*" { + permission java.security.AllPermission "", ""; +}; grant codebase "file:${com.sun.jini.jsk.home}${/}lib${/}jsk-platform.jar" { permission java.security.AllPermission "", ""; Modified: incubator/river/jtsk/trunk/src/com/sun/jini/constants/VersionConstants.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/constants/VersionConstants.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/com/sun/jini/constants/VersionConstants.java (original) +++ incubator/river/jtsk/trunk/src/com/sun/jini/constants/VersionConstants.java Thu Apr 15 01:11:12 2010 @@ -25,5 +25,5 @@ package com.sun.jini.constants; */ public interface VersionConstants { /** Current version of the Apache River release */ - String SERVER_VERSION = "2.1.2"; + String SERVER_VERSION = "2.2.0"; } Modified: incubator/river/jtsk/trunk/src/com/sun/jini/norm/NormServerBaseImpl.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/norm/NormServerBaseImpl.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/com/sun/jini/norm/NormServerBaseImpl.java (original) +++ incubator/river/jtsk/trunk/src/com/sun/jini/norm/NormServerBaseImpl.java Thu Apr 15 01:11:12 2010 @@ -26,7 +26,6 @@ import java.io.OutputStream; import java.rmi.MarshalledObject; import java.rmi.NoSuchObjectException; import java.rmi.RemoteException; -import java.rmi.server.RMIClassLoader; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.Collection; @@ -44,13 +43,10 @@ import java.util.logging.Logger; import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; -import net.jini.admin.Administrable; -import net.jini.admin.JoinAdmin; import net.jini.config.Configuration; import net.jini.config.ConfigurationException; import net.jini.config.ConfigurationProvider; import net.jini.config.NoSuchEntryException; -import net.jini.core.constraint.RemoteMethodControl; import net.jini.core.discovery.LookupLocator; import net.jini.core.entry.Entry; import net.jini.core.event.EventRegistration; @@ -77,7 +73,6 @@ import net.jini.security.BasicProxyPrepa import net.jini.security.ProxyPreparer; import net.jini.security.TrustVerifier; import net.jini.security.proxytrust.ServerProxyTrust; -import net.jini.security.proxytrust.TrustEquivalence; import com.sun.jini.config.Config; import com.sun.jini.constants.ThrowableConstants; @@ -88,7 +83,6 @@ import com.sun.jini.landlord.LandlordUti import com.sun.jini.landlord.LeaseFactory; import com.sun.jini.landlord.LeasePeriodPolicy; import com.sun.jini.landlord.LocalLandlord; -import com.sun.jini.logging.Levels; import com.sun.jini.lookup.entry.BasicServiceType; import com.sun.jini.norm.event.EventType; import com.sun.jini.norm.event.EventTypeGenerator; @@ -99,6 +93,9 @@ import com.sun.jini.start.LifeCycle; import com.sun.jini.reliableLog.LogException; import com.sun.jini.reliableLog.LogHandler; import com.sun.jini.thread.InterruptedStatusThread; +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.loader.CodebaseAccessClassLoader; +import net.jini.security.proxytrust.TrustEquivalence; /** * Base class for implementations of NormServer. Provides a complete @@ -297,7 +294,7 @@ abstract class NormServerBaseImpl "Adding lease of class {0} with annotation {1}", new Object[] { leaseToRenew.getClass(), - RMIClassLoader.getClassAnnotation(lc) }); + CodebaseAccessClassLoader.getClassAnnotation(lc) }); } // Add the lease to the set Modified: incubator/river/jtsk/trunk/src/com/sun/jini/outrigger/EntryRep.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/outrigger/EntryRep.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/com/sun/jini/outrigger/EntryRep.java (original) +++ incubator/river/jtsk/trunk/src/com/sun/jini/outrigger/EntryRep.java Thu Apr 15 01:11:12 2010 @@ -34,12 +34,10 @@ import java.lang.reflect.Modifier; import java.net.MalformedURLException; import java.rmi.MarshalException; import java.rmi.UnmarshalException; -import java.rmi.server.RMIClassLoader; import java.security.DigestOutputStream; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.Comparator; import java.util.WeakHashMap; import java.util.logging.Logger; @@ -50,6 +48,8 @@ import net.jini.id.Uuid; import net.jini.id.UuidFactory; import net.jini.io.MarshalledInstance; import net.jini.loader.ClassLoading; +import net.jini.loader.CodebaseAccessClassLoader; +import net.jini.space.JavaSpace; /** * An EntryRep object contains a packaged @@ -234,7 +234,7 @@ class EntryRep implements StorableResour if (validate) ensureValidClass(realClass); className = realClass.getName(); - codebase = RMIClassLoader.getClassAnnotation(realClass); + codebase = CodebaseAccessClassLoader.getClassAnnotation(realClass); /* * Build up the per-field and superclass information through @@ -489,6 +489,10 @@ class EntryRep implements StorableResour } catch (MarshalException e) { // because we call findHash() w/ false, should never happen throw new AssertionError(e); + } catch (IOException e) { + // see above + throw throwNewUnusableEntryException("I/O Error " + + "associated with entry of type " + className, e); } } Modified: incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupImpl.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupImpl.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupImpl.java (original) +++ incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupImpl.java Thu Apr 15 01:11:12 2010 @@ -32,7 +32,6 @@ import java.rmi.Remote; import java.rmi.RemoteException; import java.rmi.activation.*; import java.rmi.server.ExportException; -import java.rmi.server.RMIClassLoader; import java.rmi.server.RemoteObject; import java.rmi.server.UnicastRemoteObject; import java.security.AccessController; @@ -55,6 +54,7 @@ import net.jini.export.Exporter; import net.jini.export.ProxyAccessor; import net.jini.jeri.BasicJeriExporter; import net.jini.jeri.tcp.TcpServerEndpoint; +import net.jini.loader.CodebaseAccessClassLoader; import net.jini.security.BasicProxyPreparer; import net.jini.security.ProxyPreparer; import net.jini.security.Security; @@ -617,7 +617,7 @@ public class ActivationGroupImpl extends *

Otherwise: * *

The class for the object is loaded by invoking {@link - * RMIClassLoader#loadClass(String,String) RMIClassLoader.loadClass} + * CodebaseAccessClassLoader#loadClass(String,String) CodebaseAccessClassLoader.loadClass} * passing the class location (obtained by invoking {@link * ActivationDesc#getLocation getLocation} on the activation * descriptor) and the class name (obtained by invoking {@link @@ -693,7 +693,7 @@ public class ActivationGroupImpl extends } String className = desc.getClassName(); - final Class cl = RMIClassLoader.loadClass(desc.getLocation(), + final Class cl = CodebaseAccessClassLoader.loadClass(desc.getLocation(), className); final Thread t = Thread.currentThread(); final ClassLoader savedCcl = t.getContextClassLoader(); Modified: incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupInit.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupInit.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupInit.java (original) +++ incubator/river/jtsk/trunk/src/com/sun/jini/phoenix/ActivationGroupInit.java Thu Apr 15 01:11:12 2010 @@ -22,9 +22,9 @@ import java.lang.reflect.Method; import java.rmi.activation.ActivationGroup; import java.rmi.activation.ActivationGroupDesc; import java.rmi.activation.ActivationGroupID; -import java.rmi.server.RMIClassLoader; import java.util.Collections; import net.jini.io.MarshalInputStream; +import net.jini.loader.CodebaseAccessClassLoader; /** * This is the bootstrap code to start a virtual machine (VM) executing an @@ -70,7 +70,7 @@ class ActivationGroupInit { ActivationGroupID id = (ActivationGroupID)in.readObject(); ActivationGroupDesc desc = (ActivationGroupDesc)in.readObject(); long incarnation = in.readLong(); - Class cl = RMIClassLoader.loadClass(desc.getLocation(), + Class cl = CodebaseAccessClassLoader.loadClass(desc.getLocation(), desc.getClassName()); try { Method create = Modified: incubator/river/jtsk/trunk/src/com/sun/jini/reggie/EntryClassBase.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/reggie/EntryClassBase.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/com/sun/jini/reggie/EntryClassBase.java (original) +++ incubator/river/jtsk/trunk/src/com/sun/jini/reggie/EntryClassBase.java Thu Apr 15 01:11:12 2010 @@ -17,9 +17,8 @@ */ package com.sun.jini.reggie; -import java.rmi.server.RMIClassLoader; -import java.io.IOException; import java.io.Serializable; +import net.jini.loader.CodebaseAccessClassLoader; /** * An EntryClass annotated with a codebase. @@ -52,7 +51,7 @@ class EntryClassBase implements Serializ /** Sets the codebase to the codebase of the given class. */ public void setCodebase(Class cls) { - codebase = RMIClassLoader.getClassAnnotation(cls); + codebase = CodebaseAccessClassLoader.getClassAnnotation(cls); } /** Modified: incubator/river/jtsk/trunk/src/manifest/jsk-platform.mf URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/manifest/jsk-platform.mf?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/manifest/jsk-platform.mf (original) +++ incubator/river/jtsk/trunk/src/manifest/jsk-platform.mf Thu Apr 15 01:11:12 2010 @@ -1,2 +1,4 @@ Manifest-Version: 1.0 Class-Path: jsk-resources.jar +Implementation-Vendor: Apache Software Foundation +Implementation-Version: 2.2.0 Modified: incubator/river/jtsk/trunk/src/net/jini/activation/ActivationGroup.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/activation/ActivationGroup.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/activation/ActivationGroup.java (original) +++ incubator/river/jtsk/trunk/src/net/jini/activation/ActivationGroup.java Thu Apr 15 01:11:12 2010 @@ -23,10 +23,10 @@ import java.rmi.activation.ActivationExc import java.rmi.activation.ActivationGroupDesc; import java.rmi.activation.ActivationGroupID; import java.rmi.activation.ActivationID; -import java.rmi.server.RMIClassLoader; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; import net.jini.export.Exporter; +import net.jini.loader.CodebaseAccessClassLoader; import net.jini.security.Security; /** @@ -129,7 +129,7 @@ public abstract class ActivationGroup Class cl = (Class) Security.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws Exception { - return RMIClassLoader.loadClass(location, className); + return CodebaseAccessClassLoader.loadClass(location, className); } }); return ActivationGroup.class.isAssignableFrom(cl); Added: incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java?rev=934258&view=auto ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java (added) +++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java Thu Apr 15 01:11:12 2010 @@ -0,0 +1,219 @@ +/* + * 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 net.jini.core.lookup; + +import java.rmi.RemoteException; +import net.jini.core.discovery.LookupLocator; + +/** + * + * @author peter + */ +public interface PortableServiceRegistrar { + /** + * An event is sent when the changed item matches the template both + * before and after the operation. + */ + int TRANSITION_MATCH_MATCH = 1 << 2; + /** + * An event is sent when the changed item matches the template before + * the operation, but doesn't match the template after the operation + * (this includes deletion of the item). + */ + int TRANSITION_MATCH_NOMATCH = 1 << 0; + /** + * An event is sent when the changed item doesn't match the template + * before the operation (this includes not existing), but does match + * the template after the operation. + */ + int TRANSITION_NOMATCH_MATCH = 1 << 1; + + /** + * Looks at all service items that match the specified template, finds + * every entry (among those service items) that either doesn't match any + * entry templates or is a subclass of at least one matching entry + * template, and returns the set of the (most specific) classes of those + * entries. Duplicate classes are eliminated, and the order of classes + * within the returned array is arbitrary. Null (not an empty array) is + * returned if there are no such entries or no matching items. If a + * returned class cannot be deserialized, that element of the returned + * array is set to null and no exception is thrown. + * + * @param tmpl template to match + * @return an array of entry Classes (attribute sets) for every service + * that matches the specified template + * @throws java.rmi.RemoteException + */ + Class[] getEntryClasses(ServiceTemplate tmpl) throws RemoteException; + + /** + * Looks at all service items that match the specified template, finds + * every entry (among those service items) that matches + * tmpl.attributeSetTemplates[setIndex], and returns the set of values + * of the specified field of those entries. Duplicate values are + * eliminated, and the order of values within the returned array is + * arbitrary. Null (not an empty array) is returned if there are no + * matching items. If a returned value cannot be deserialized, that + * element of the returned array is set to null and no exception is + * thrown. + * + * @param tmpl template to match + * @param setIndex index into tmpl.attributeSetTemplates + * @param field name of field of tmpl.attributeSetTemplates[setIndex] + * + * @return an array of objects that represents field values of entries + * associated with services that meet the specified matching + * criteria + * + * @throws NoSuchFieldException field does not name a field of the + * entry template + * @throws java.rmi.RemoteException + */ + Object[] getFieldValues(ServiceTemplate tmpl, int setIndex, String field) throws NoSuchFieldException, RemoteException; + + /** + * Returns the set of groups that this lookup service is currently a + * member of. + * + * @return a String array of groups that this lookup service is currently + * a member of. + * @throws java.rmi.RemoteException + */ + String[] getGroups() throws RemoteException; + + /** + * Returns a LookupLocator that can be used if necessary for unicast + * discovery of the lookup service. + * + * @return a LookupLocator that can be used for unicast discovery of + * the lookup service, if necessary. + * @throws java.rmi.RemoteException + */ + LookupLocator getLocator() throws RemoteException; + + /** + * Returns the service ID of the lookup service. Note that this does not + * make a remote call. A lookup service is always registered with itself + * under this service ID, and if a lookup service is configured to + * register itself with other lookup services, it will register with all + * of them using this same service ID. + * + * @return the service ID of the lookup service. + */ + ServiceID getServiceID(); + + /** + * Looks at all service items that match the specified template, and for + * every service item finds the most specific type (class or interface) + * or types the service item is an instance of that are neither equal to, + * nor a superclass of, any of the service types in the template and that + * have names that start with the specified prefix, and returns the set + * of all such types. Duplicate types are eliminated, and the order of + * types within the returned array is arbitrary. Null (not an empty + * array) is returned if there are no such types. If a returned type + * cannot be deserialized, that element of the returned array is set to + * null and no exception is thrown. + * + * @param tmpl template to match + * @param prefix class name prefix + * + * @return an array of Classes of all services that either match the + * specified template or match the specified prefix + * @throws java.rmi.RemoteException + */ + Class[] getServiceTypes(ServiceTemplate tmpl, String prefix) throws RemoteException; + + /** + * Returns the service object (i.e., just ServiceItem.service) from an + * item matching the template, or null if there is no match. If multiple + * items match the template, it is arbitrary as to which service object + * is returned. If the returned object cannot be deserialized, an + * UnmarshalException is thrown with the standard RMI semantics. + * + * @param tmpl template to match + * @return an object that represents a service that matches the + * specified template + * @throws java.rmi.RemoteException + */ + Object lookup(ServiceTemplate tmpl) throws RemoteException; + + /** + * Returns at most maxMatches items matching the template, plus the total + * number of items that match the template. The return value is never + * null, and the returned items array is only null if maxMatches is zero. + * For each returned item, if the service object cannot be deserialized, + * the service field of the item is set to null and no exception is + * thrown. Similarly, if an attribute set cannot be deserialized, that + * element of the attributeSets array is set to null and no exception + * is thrown. + * + * @param tmpl template to match + * @param maxMatches maximum number of matches to return + * @return a ServiceMatches instance that contains at most maxMatches + * items matching the template, plus the total number of items + * that match the template. The return value is never null, and + * the returned items array is only null if maxMatches is zero. + * @throws java.rmi.RemoteException + */ + ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) throws RemoteException; + + /** + * Register a new service or re-register an existing service. The method + * is defined so that it can be used in an idempotent fashion. + * Specifically, if a call to register results in a RemoteException (in + * which case the item might or might not have been registered), the + * caller can simply repeat the call to register with the same parameters, + * until it succeeds. + *

+ * To register a new service, item.serviceID should be null. In that + * case, if item.service does not equal (using MarshalledObject.equals) + * any existing item's service object, then a new service ID will be + * assigned and included in the returned ServiceRegistration. The + * service ID is unique over time and space with respect to all other + * service IDs generated by all lookup services. If item.service does + * equal an existing item's service object, the existing item is first + * deleted from the lookup service (even if it has different attributes) + * and its lease is cancelled, but that item's service ID is reused for + * the newly registered item. + *

+ * To re-register an existing service, or to register the service in any + * other lookup service, item.serviceID should be set to the same service + * ID that was returned by the initial registration. If an item is + * already registered under the same service ID, the existing item is + * first deleted (even if it has different attributes or a different + * service instance) and its lease is cancelled. Note that service + * object equality is not checked in this case, to allow for reasonable + * evolution of the service (e.g., the serialized form of the stub + * changes, or the service implements a new interface). + *

+ * Any duplicate attribute sets included in a service item are eliminated + * in the stored representation of the item. The lease duration request + * is not exact; the returned lease is allowed to have a shorter (but not + * longer) duration than what was requested. The registration is + * persistent across restarts (crashes) of the lookup service until the + * lease expires or is cancelled. + * + * @param item service item to register + * @param leaseDuration requested lease duration, in milliseconds + * @return a ServiceRegistration in this lookup service for the specified + * service item + * @throws java.rmi.RemoteException + */ + ServiceRegistration register(ServiceItem item, long leaseDuration) throws RemoteException; + +} Propchange: incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/river/jtsk/trunk/src/net/jini/core/lookup/ServiceRegistrar.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/ServiceRegistrar.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/core/lookup/ServiceRegistrar.java (original) +++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/ServiceRegistrar.java Thu Apr 15 01:11:12 2010 @@ -19,7 +19,6 @@ package net.jini.core.lookup; import java.rmi.RemoteException; import java.rmi.MarshalledObject; -import net.jini.core.discovery.LookupLocator; import net.jini.core.event.EventRegistration; import net.jini.core.event.RemoteEventListener; @@ -40,107 +39,7 @@ import net.jini.core.event.RemoteEventLi * * @since 1.0 */ -public interface ServiceRegistrar { - - /** - * Register a new service or re-register an existing service. The method - * is defined so that it can be used in an idempotent fashion. - * Specifically, if a call to register results in a RemoteException (in - * which case the item might or might not have been registered), the - * caller can simply repeat the call to register with the same parameters, - * until it succeeds. - *

- * To register a new service, item.serviceID should be null. In that - * case, if item.service does not equal (using MarshalledObject.equals) - * any existing item's service object, then a new service ID will be - * assigned and included in the returned ServiceRegistration. The - * service ID is unique over time and space with respect to all other - * service IDs generated by all lookup services. If item.service does - * equal an existing item's service object, the existing item is first - * deleted from the lookup service (even if it has different attributes) - * and its lease is cancelled, but that item's service ID is reused for - * the newly registered item. - *

- * To re-register an existing service, or to register the service in any - * other lookup service, item.serviceID should be set to the same service - * ID that was returned by the initial registration. If an item is - * already registered under the same service ID, the existing item is - * first deleted (even if it has different attributes or a different - * service instance) and its lease is cancelled. Note that service - * object equality is not checked in this case, to allow for reasonable - * evolution of the service (e.g., the serialized form of the stub - * changes, or the service implements a new interface). - *

- * Any duplicate attribute sets included in a service item are eliminated - * in the stored representation of the item. The lease duration request - * is not exact; the returned lease is allowed to have a shorter (but not - * longer) duration than what was requested. The registration is - * persistent across restarts (crashes) of the lookup service until the - * lease expires or is cancelled. - * - * @param item service item to register - * @param leaseDuration requested lease duration, in milliseconds - * @return a ServiceRegistration in this lookup service for the specified - * service item - * @throws java.rmi.RemoteException - */ - ServiceRegistration register(ServiceItem item, long leaseDuration) - throws RemoteException; - - /** - * Returns the service object (i.e., just ServiceItem.service) from an - * item matching the template, or null if there is no match. If multiple - * items match the template, it is arbitrary as to which service object - * is returned. If the returned object cannot be deserialized, an - * UnmarshalException is thrown with the standard RMI semantics. - * - * @param tmpl template to match - * @return an object that represents a service that matches the - * specified template - * @throws java.rmi.RemoteException - */ - Object lookup(ServiceTemplate tmpl) throws RemoteException; - - /** - * Returns at most maxMatches items matching the template, plus the total - * number of items that match the template. The return value is never - * null, and the returned items array is only null if maxMatches is zero. - * For each returned item, if the service object cannot be deserialized, - * the service field of the item is set to null and no exception is - * thrown. Similarly, if an attribute set cannot be deserialized, that - * element of the attributeSets array is set to null and no exception - * is thrown. - * - * @param tmpl template to match - * @param maxMatches maximum number of matches to return - * @return a ServiceMatches instance that contains at most maxMatches - * items matching the template, plus the total number of items - * that match the template. The return value is never null, and - * the returned items array is only null if maxMatches is zero. - * @throws java.rmi.RemoteException - */ - ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) - throws RemoteException; - - /** - * An event is sent when the changed item matches the template before - * the operation, but doesn't match the template after the operation - * (this includes deletion of the item). - */ - int TRANSITION_MATCH_NOMATCH = 1 << 0; - - /** - * An event is sent when the changed item doesn't match the template - * before the operation (this includes not existing), but does match - * the template after the operation. - */ - int TRANSITION_NOMATCH_MATCH = 1 << 1; - - /** - * An event is sent when the changed item matches the template both - * before and after the operation. - */ - int TRANSITION_MATCH_MATCH = 1 << 2; +public interface ServiceRegistrar extends PortableServiceRegistrar { /** * Registers for event notification. The registration is leased; the @@ -170,101 +69,4 @@ public interface ServiceRegistrar { MarshalledObject handback, long leaseDuration) throws RemoteException; - - /** - * Looks at all service items that match the specified template, finds - * every entry (among those service items) that either doesn't match any - * entry templates or is a subclass of at least one matching entry - * template, and returns the set of the (most specific) classes of those - * entries. Duplicate classes are eliminated, and the order of classes - * within the returned array is arbitrary. Null (not an empty array) is - * returned if there are no such entries or no matching items. If a - * returned class cannot be deserialized, that element of the returned - * array is set to null and no exception is thrown. - * - * @param tmpl template to match - * @return an array of entry Classes (attribute sets) for every service - * that matches the specified template - * @throws java.rmi.RemoteException - */ - Class[] getEntryClasses(ServiceTemplate tmpl) throws RemoteException; - - /** - * Looks at all service items that match the specified template, finds - * every entry (among those service items) that matches - * tmpl.attributeSetTemplates[setIndex], and returns the set of values - * of the specified field of those entries. Duplicate values are - * eliminated, and the order of values within the returned array is - * arbitrary. Null (not an empty array) is returned if there are no - * matching items. If a returned value cannot be deserialized, that - * element of the returned array is set to null and no exception is - * thrown. - * - * @param tmpl template to match - * @param setIndex index into tmpl.attributeSetTemplates - * @param field name of field of tmpl.attributeSetTemplates[setIndex] - * - * @return an array of objects that represents field values of entries - * associated with services that meet the specified matching - * criteria - * - * @throws NoSuchFieldException field does not name a field of the - * entry template - * @throws java.rmi.RemoteException - */ - Object[] getFieldValues(ServiceTemplate tmpl, int setIndex, String field) - throws NoSuchFieldException, RemoteException; - - /** - * Looks at all service items that match the specified template, and for - * every service item finds the most specific type (class or interface) - * or types the service item is an instance of that are neither equal to, - * nor a superclass of, any of the service types in the template and that - * have names that start with the specified prefix, and returns the set - * of all such types. Duplicate types are eliminated, and the order of - * types within the returned array is arbitrary. Null (not an empty - * array) is returned if there are no such types. If a returned type - * cannot be deserialized, that element of the returned array is set to - * null and no exception is thrown. - * - * @param tmpl template to match - * @param prefix class name prefix - * - * @return an array of Classes of all services that either match the - * specified template or match the specified prefix - * @throws java.rmi.RemoteException - */ - Class[] getServiceTypes(ServiceTemplate tmpl, String prefix) - throws RemoteException; - - /** - * Returns the service ID of the lookup service. Note that this does not - * make a remote call. A lookup service is always registered with itself - * under this service ID, and if a lookup service is configured to - * register itself with other lookup services, it will register with all - * of them using this same service ID. - * - * @return the service ID of the lookup service. - */ - ServiceID getServiceID(); - - /** - * Returns a LookupLocator that can be used if necessary for unicast - * discovery of the lookup service. - * - * @return a LookupLocator that can be used for unicast discovery of - * the lookup service, if necessary. - * @throws java.rmi.RemoteException - */ - LookupLocator getLocator() throws RemoteException; - - /** - * Returns the set of groups that this lookup service is currently a - * member of. - * - * @return a String array of groups that this lookup service is currently - * a member of. - * @throws java.rmi.RemoteException - */ - String[] getGroups() throws RemoteException; } Added: incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java?rev=934258&view=auto ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java (added) +++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java Thu Apr 15 01:11:12 2010 @@ -0,0 +1,59 @@ +/* + * 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 net.jini.core.lookup; + +import java.rmi.RemoteException; +import net.jini.io.CDCMarshalledObject; +import net.jini.core.event.EventRegistration; +import net.jini.core.event.RemoteEventListener; + +/** + * + * @author Peter Firmstone + */ +public interface StreamingServiceRegistrar extends PortableServiceRegistrar{ + + /** + * Registers for event notification. The registration is leased; the + * lease expiration request is not exact. The registration is persistent + * across restarts (crashes) of the lookup service until the lease expires + * or is cancelled. The event ID in the returned EventRegistration is + * unique at least with respect to all other active event registrations + * in this lookup service with different service templates or transitions. + *

+ * While the event registration is in effect, a ServiceEvent is sent to + * the specified listener whenever a register, lease cancellation or + * expiration, or attribute change operation results in an item changing + * state in a way that satisfies the template and transition combination. + * + * @param tmpl template to match + * @param transitions bitwise OR of any non-empty set of transition values + * @param listener listener to send events to + * @param handback object to include in every ServiceEvent generated + * @param leaseDuration requested lease duration + * @return an EventRegistration object to the entity that registered the + * specified remote listener + * @throws java.rmi.RemoteException + */ + EventRegistration notify(ServiceTemplate tmpl, + int transitions, + RemoteEventListener listener, + CDCMarshalledObject handback, + long leaseDuration) + throws RemoteException; +} Propchange: incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/river/jtsk/trunk/src/net/jini/io/CDCMarshalledObject.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/CDCMarshalledObject.java?rev=934258&view=auto ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/CDCMarshalledObject.java (added) +++ incubator/river/jtsk/trunk/src/net/jini/io/CDCMarshalledObject.java Thu Apr 15 01:11:12 2010 @@ -0,0 +1,281 @@ +/* + * 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 net.jini.io; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import net.jini.io.context.IntegrityEnforcement; + +/** + * This is an experimental implementation and may be subject to change or + * removal. + * A CDCMarshalledObject contains an object in serialized + * form. The contained object can be deserialized on demand when + * explicitly requested. This allows an object to be sent from one VM + * to another in a way that allows the receiver to control when and if + * the object is deserialized. + *

+ * The contained object is specified at construction time and can + * either be provided in unserialized or serialized form. If provided + * in unserialized form it will be serialized during construction + * with the serialization semantics defined by + * MarshalOutputStream. In particular, classes are annotated + * with a codebase URL from which the class can be loaded (if available). + *

+ * If the CDCMarshalledObject needs to deserialize the + * contained object then the contained object will be deserialized with the + * deserialization semantics defined by MarshalInputStream. + * In particular, the codebase annotations associated with the contained + * object may be used to load classes referenced by the contained object. + *

+ * CDCMarshalledObject provides functionality similar to + * java.rmi.MarshalledObject, but additionally provides + * for the verification of codebase integrity. Unlike + * java.rmi.MarshalledObject, it does not perform remote + * object-to-stub replacement. + *

+ * CDCMarshalledObject differes from MarshalledInstance + * in lacking a dependency upon java.rmi.MarshalledObject as the CDC Personal Profile + * lacks the rmi server implementation. Convert provides methods + * for conversion between the various implementations. + *

+ * + * + * @param T - Type of Object + * @author Peter Firmstone. + * @since 2.2.0 + */ +public class CDCMarshalledObject implements Serializable { + + /** + * @serial Bytes of serialized representation. If objBytes is + * null then the object marshalled was a null + * reference. + */ + private byte[] objBytes; + + /** + * @serial Bytes of location annotations, which are ignored by + * equals. If locBytes is null, there were no + * non-null annotations during marshalling. + */ + private byte[] locBytes; + + /** + * @serial Stored hash code of contained object. + * + * @see #hashCode + */ + private final int hash; + + private final PackageVersion packageVersion; + + static final long serialVersionUID = 1L; + + CDCMarshalledObject(MarshalledObject mo, PackageVersion pv){ + // Don't worry about defensive copies this is package private + objBytes = mo.objBytes; + locBytes = mo.locBytes; + hash = mo.hash; + packageVersion = pv; + } + + /** + * Creates a new MarshalledInstance that contains the + * marshalled representation of the current state of the supplied + * object. The object is serialized with the semantics defined by + * MarshalOutputStream. The output stream used to marshal the + * object implements {@link ObjectStreamContext} and returns an empty + * collection from its {@link ObjectStreamContext#getObjectStreamContext + * getObjectStreamContext} method. + * + * @param obj The Object to be contained in the new + * MarshalledInstance + * @throws IOException if the object cannot be serialized + */ + public CDCMarshalledObject(T obj) throws IOException { + this(obj, Collections.EMPTY_SET); + } + + /** + * Creates a new MarshalledInstance that contains the + * marshalled representation of the current state of the supplied + * object. The object is serialized with the semantics defined by + * MarshalOutputStream. The output stream used to marshal the + * object implements {@link ObjectStreamContext} and returns the given + * collection from its {@link ObjectStreamContext#getObjectStreamContext + * getObjectStreamContext} method. + * + * @param obj The Object to be contained in the new + * MarshalledInstance + * @param context the collection of context information objects + * @throws IOException if the object cannot be serialized + * @throws NullPointerException if context is null + */ + public CDCMarshalledObject(T obj, Collection context) + throws IOException + { + if (context == null) throw new NullPointerException(); + if (obj == null) { + hash = 13; // null hash for java.rmi.MarshalledObject + objBytes = null; + locBytes = null; + packageVersion = null; + return; + } + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + ByteArrayOutputStream lout = new ByteArrayOutputStream(); + MarshalledInstanceOutputStream out = + new MarshalledInstanceOutputStream(bout, lout, context); + out.writeObject(obj); + out.flush(); + objBytes = bout.toByteArray(); + // locBytes is null if no annotations + locBytes = (out.hadAnnotations() ? lout.toByteArray() : null); + + // Calculate hash from the marshalled representation of object + // so the hashcode will be comparable when sent between VMs. + // + // Note: This calculation must match the calculation in + // java.rmi.MarshalledObject since we use this hash + // in the converted MarshalledObject. The reverse is + // also true in that we use the MarshalledObject's + // hash for our hash. (see the MarshalledInstance( + // MarshalledObject) constructor) + // + int h = 0; + for (int i = 0; i < objBytes.length; i++) { + h = 31 * h + objBytes[i]; + } + hash = h; + packageVersion = PackageVersion.getInstance(obj); + } + + MarshalledObject asMarshalledObject(){ + MarshalledObject mo = new MarshalledObject(); + // Don't worry about defensive copies, this is package private. + mo.objBytes = objBytes; + mo.locBytes = locBytes; + mo.hash = hash; + return mo; + } + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj instanceof CDCMarshalledObject) { + CDCMarshalledObject other = (CDCMarshalledObject) obj; + if (hash != other.hash) { + return false; + } + return Arrays.equals(objBytes, other.objBytes); + } + return false; + } + + public boolean fullyEquals(Object obj) { + if (equals(obj)) { + CDCMarshalledObject other = (CDCMarshalledObject) obj; + return Arrays.equals(locBytes, other.locBytes); + } + return false; + } + + public PackageVersion getPackageVersion(){ + return packageVersion; + } + + public T get(final boolean verifyCodebaseIntegrity) throws IOException, ClassNotFoundException { + return get(null, verifyCodebaseIntegrity, null, null); + } + + public T get(ClassLoader defaultLoader, final boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) throws IOException, ClassNotFoundException { + if (objBytes == null) { + // must have been a null object + return null; + } + if (context == null) { + context = Collections.singleton(new IntegrityEnforcement() { + + public boolean integrityEnforced() { + return verifyCodebaseIntegrity; + } + }); + } + ByteArrayInputStream bin = new ByteArrayInputStream(objBytes); + ByteArrayInputStream lin = locBytes == null ? null : new ByteArrayInputStream(locBytes); + MarshalledInstanceInputStream in = new MarshalledInstanceInputStream(bin, lin, defaultLoader, verifyCodebaseIntegrity, verifierLoader, context); + in.useCodebaseAnnotations(); + @SuppressWarnings("unchecked") + T obj = (T) in.readObject(); + in.close(); + return obj; + } + + /** + * Returns the hash code for this MarshalledInstance. + * The hash code is calculated only from the serialized form + * of the contained object. + * @return The hash code for this object + */ + @Override + public int hashCode() { + return hash; + } + + private void writeObject(ObjectOutputStream out) throws IOException{ + out.defaultWriteObject(); + } + + /** + * Verify the case of null contained object. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + + // If contained object is null, then hash and locBytes must be + // proper + // + if ((objBytes == null) && ((hash != 13) || (locBytes != null))) + throw new InvalidObjectException("Bad hash or annotation"); + // Defensive copy of arrays to prevent unmarshalling attack using + // stolen reference for mutable fields. array.clone() not working? jdk1.6 + objBytes = Arrays.copyOf(objBytes, objBytes.length); + locBytes = Arrays.copyOf(locBytes, locBytes.length); + } + + /** + * Protect against missing superclass. + */ + private void readObjectNoData() throws ObjectStreamException { + throw new InvalidObjectException("Bad class hierarchy"); + } +} Propchange: incubator/river/jtsk/trunk/src/net/jini/io/CDCMarshalledObject.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/river/jtsk/trunk/src/net/jini/io/Convert.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/Convert.java?rev=934258&view=auto ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/Convert.java (added) +++ incubator/river/jtsk/trunk/src/net/jini/io/Convert.java Thu Apr 15 01:11:12 2010 @@ -0,0 +1,126 @@ +/* + * 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 net.jini.io; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Collections; + +/** + * Rather than utilise a static class, an empty object class can be utilised + * for conversion of a particular Object type, to preserve Generic semantics. + * + * Note that java.rmi.MarshalledObject didn't take Generic parameters + * until Java 6 or jdk 1.6, so this doesn't compile with jdk1.5 however it + * will run on Java 5 if compiled with jdk1.6 + * + * @param T - Generic Type Parameter of contained object. + * @author Peter Firmstone + */ +public class Convert { + @SuppressWarnings("unchecked") + private java.rmi.MarshalledObject + toRmiMarshalledObject(net.jini.io.MarshalledObject privateMO){ + // To create a java.rmi.MarshalledObject with previously + // serialized data we first create a private + // net.jini.io.MarshalledObject with the + // data and then convert it to the final object by changing + // the class during readObject(). (See resolveClass() in + // ToMOInputStream) + // + java.rmi.MarshalledObject mo = null; + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(privateMO); + oos.flush(); + byte[] bytes = baos.toByteArray(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ToMOInputStream(bais); + mo = (java.rmi.MarshalledObject)ois.readObject(); + } catch (IOException ioe) { + throw new AssertionError(ioe); + } catch (ClassNotFoundException cnfe) { + throw new AssertionError(cnfe); + } + return mo; + } + + private net.jini.io.MarshalledObject toJiniMarshalledObject( + java.rmi.MarshalledObject instance){ + net.jini.io.MarshalledObject privateMO = null; + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(instance); + oos.flush(); + byte[] bytes = baos.toByteArray(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new FromMOInputStream(bais); + privateMO = (net.jini.io.MarshalledObject) ois.readObject(); + } catch (IOException ioe) { + throw new AssertionError(ioe); + } catch (ClassNotFoundException cnfe) { + throw new AssertionError(cnfe); + } + return privateMO; + } + + public java.rmi.MarshalledObject + toRmiMarshalledObject(CDCMarshalledObject instance){ + if ( instance == null ) throw new NullPointerException("null reference"); + return toRmiMarshalledObject(instance.asMarshalledObject()); + } + + public java.rmi.MarshalledObject + toRmiMarshalledObject(MarshalledInstance instance){ + if ( instance == null ) throw new NullPointerException("null reference"); + return toRmiMarshalledObject(instance.asMarshalledObject()); + } + + public MarshalledInstance + toMarshalledInstance(java.rmi.MarshalledObject instance){ + if ( instance == null ) throw new NullPointerException("null reference"); + net.jini.io.MarshalledObject obj = toJiniMarshalledObject(instance); + if ( obj == null ) throw new NullPointerException("null reference"); + return new MarshalledInstance(obj); + } + + public MarshalledInstance + toMarshalledInstance(CDCMarshalledObject instance){ + if ( instance == null ) throw new NullPointerException("null reference"); + return new MarshalledInstance(instance.asMarshalledObject()); + } + + public CDCMarshalledObject + toCDCMarshalledObject(java.rmi.MarshalledObject instance){ + if ( instance == null ) throw new NullPointerException("null reference"); + return toCDCMarshalledObject(instance, null); + } + + public CDCMarshalledObject + toCDCMarshalledObject( + java.rmi.MarshalledObject instance, PackageVersion version){ + if ( instance == null ) throw new NullPointerException("null reference"); + return new CDCMarshalledObject(toJiniMarshalledObject(instance), + version); + } +} Propchange: incubator/river/jtsk/trunk/src/net/jini/io/Convert.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/river/jtsk/trunk/src/net/jini/io/FromMOInputStream.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/FromMOInputStream.java?rev=934258&view=auto ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/FromMOInputStream.java (added) +++ incubator/river/jtsk/trunk/src/net/jini/io/FromMOInputStream.java Thu Apr 15 01:11:12 2010 @@ -0,0 +1,38 @@ +/* + * 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 net.jini.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; + +class FromMOInputStream extends ObjectInputStream { + + public FromMOInputStream(InputStream in) throws IOException { + super(in); + } + + @Override + protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + if (desc.getName().equals("java.rmi.MarshalledObject")) { + return net.jini.io.MarshalledObject.class; + } + return super.resolveClass(desc); + } +} Propchange: incubator/river/jtsk/trunk/src/net/jini/io/FromMOInputStream.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/river/jtsk/trunk/src/net/jini/io/MarshalInputStream.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalInputStream.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/MarshalInputStream.java (original) +++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalInputStream.java Thu Apr 15 01:11:12 2010 @@ -23,19 +23,18 @@ import java.io.InputStream; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectStreamClass; -import java.net.MalformedURLException; -import java.rmi.server.RMIClassLoader; import java.util.Collection; import java.util.HashMap; import java.util.Map; import net.jini.loader.ClassLoading; +import net.jini.loader.CodebaseAccessClassLoader; import net.jini.security.Security; /** * An extension of ObjectInputStream that implements the * dynamic class loading semantics of Java(TM) Remote Method * Invocation (Java RMI) argument and result - * unmarshalling (using {@link RMIClassLoader}). A + * unmarshalling (using {@link CodebaseAccessClassLoader}). A * MarshalInputStream is intended to read data written by * a corresponding {@link MarshalOutputStream}. * @@ -46,10 +45,10 @@ import net.jini.security.Security; * class descriptors in the stream using {@link ClassLoading#loadClass * ClassLoading.loadClass} and {@link ClassLoading#loadProxyClass * ClassLoading.loadProxyClass} (which, in turn, use {@link - * RMIClassLoader#loadClass(String,String,ClassLoader) - * RMIClassLoader.loadClass} and {@link - * RMIClassLoader#loadProxyClass(String,String[],ClassLoader) - * RMIClassLoader.loadProxyClass}), optionally with codebase + * CodebaseAccessClassLoader#loadClass(String,String,ClassLoader) + * CodebaseAccessClassLoader.loadClass} and {@link + * CodebaseAccessClassLoader#loadProxyClass(String,String[],ClassLoader) + * CodebaseAccessClassLoader.loadProxyClass}), optionally with codebase * annotation strings written by a MarshalOutputStream. * *

By default, a MarshalInputStream ignores all Modified: incubator/river/jtsk/trunk/src/net/jini/io/MarshalOutputStream.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalOutputStream.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/MarshalOutputStream.java (original) +++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalOutputStream.java Thu Apr 15 01:11:12 2010 @@ -21,14 +21,14 @@ package net.jini.io; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; -import java.rmi.server.RMIClassLoader; import java.util.Collection; +import net.jini.loader.CodebaseAccessClassLoader; /** * An extension of ObjectOutputStream that implements the * dynamic class loading semantics of Java(TM) Remote Method Invocation * (Java RMI) argument and result - * marshalling (using {@link RMIClassLoader}). A + * marshalling (using {@link CodebaseAccessClassLoader}). A * MarshalOutputStream writes data that is intended to be * written by a corresponding {@link MarshalInputStream}. * @@ -37,8 +37,8 @@ import java.util.Collection; * ObjectOutputStream#annotateClass annotateClass} and {@link * ObjectOutputStream#annotateProxyClass annotateProxyClass} to * annotate class descriptors in the stream with codebase strings - * obtained using {@link RMIClassLoader#getClassAnnotation - * RMIClassLoader.getClassAnnotation}. + * obtained using {@link CodebaseAccessClassLoader#getClassAnnotation + * CodebaseAccessClassLoader.getClassAnnotation}. * *

MarshalOutputStream writes class annotations to its * own stream; a subclass may override the {@link #writeAnnotation @@ -111,8 +111,8 @@ public class MarshalOutputStream *

MarshalOutputStream implements this method as * follows: * - *

This method invokes {@link RMIClassLoader#getClassAnnotation - * RMIClassLoader.getClassAnnotation} with cl to get + *

This method invokes {@link CodebaseAccessClassLoader#getClassAnnotation + * CodebaseAccessClassLoader.getClassAnnotation} with cl to get * the appropriate class annotation string value (possibly * null), and then it invokes this stream's {@link * #writeAnnotation writeAnnotation} method with that string to @@ -127,7 +127,7 @@ public class MarshalOutputStream * null **/ protected void annotateClass(Class cl) throws IOException { - writeAnnotation(RMIClassLoader.getClassAnnotation(cl)); + writeAnnotation(CodebaseAccessClassLoader.getClassAnnotation(cl)); } /** @@ -137,8 +137,8 @@ public class MarshalOutputStream *

MarshalOutputStream implements this method as * follows: * - *

This method invokes {@link RMIClassLoader#getClassAnnotation - * RMIClassLoader.getClassAnnotation} with cl to get + *

This method invokes {@link CodebaseAccessClassLoader#getClassAnnotation + * CodebaseAccessClassLoader.getClassAnnotation} with cl to get * the appropriate class annotation string value (possibly * null), and then it invokes this stream's {@link * #writeAnnotation writeAnnotation} method with that string to @@ -153,7 +153,7 @@ public class MarshalOutputStream * null **/ protected void annotateProxyClass(Class cl) throws IOException { - writeAnnotation(RMIClassLoader.getClassAnnotation(cl)); + writeAnnotation(CodebaseAccessClassLoader.getClassAnnotation(cl)); } /** Modified: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java?rev=934258&r1=934257&r2=934258&view=diff ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java (original) +++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java Thu Apr 15 01:11:12 2010 @@ -20,13 +20,10 @@ package net.jini.io; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.ObjectStreamClass; import java.io.ObjectStreamException; -import java.io.OutputStream; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; @@ -69,7 +66,7 @@ import net.jini.io.context.IntegrityEnfo * @author Sun Microsystems, Inc. * @since 2.0 */ -public class MarshalledInstance implements Serializable { +public class MarshalledInstance implements Serializable { /** * @serial Bytes of serialized representation. If objBytes is @@ -94,6 +91,14 @@ public class MarshalledInstance implemen static final long serialVersionUID = -5187033771082433496L; + MarshalledInstance(net.jini.io.MarshalledObject mo){ + if ( mo == null) throw new NullPointerException("MarshalledObject was null"); + // for some reason objBytes.clone() throws a null pointer exception. + objBytes = Arrays.copyOf(mo.objBytes, mo.objBytes.length); + locBytes = mo.locBytes; + hash = mo.hash; + } + /** * Creates a new MarshalledInstance that contains the * marshalled representation of the current state of the supplied @@ -107,7 +112,7 @@ public class MarshalledInstance implemen * MarshalledInstance * @throws IOException if the object cannot be serialized */ - public MarshalledInstance(Object obj) throws IOException { + public MarshalledInstance(T obj) throws IOException { this(obj, Collections.EMPTY_SET); } @@ -126,7 +131,7 @@ public class MarshalledInstance implemen * @throws IOException if the object cannot be serialized * @throws NullPointerException if context is null */ - public MarshalledInstance(Object obj, Collection context) + public MarshalledInstance(T obj, Collection context) throws IOException { if (context == null) @@ -176,8 +181,10 @@ public class MarshalledInstance implemen * the object the new MarshalledInstance should * contain * @throws NullPointerException if mo is null + * @deprecated As of Release 2.2.0 replaced by {@link Convert} */ - public MarshalledInstance(java.rmi.MarshalledObject mo) { + @Deprecated + public MarshalledInstance(java.rmi.MarshalledObject mo) { if (mo == null) throw new NullPointerException(); @@ -216,11 +223,14 @@ public class MarshalledInstance implemen *

* The object contained in this MarshalledInstance * object will not be unmarshalled as part of this call. + * @deprecated As of Release 2.2.0 replaced by {@link Convert} * @return A new MarshalledObject which * contains an object equivalent to the object * contained in this MarshalledInstance */ - public java.rmi.MarshalledObject convertToMarshalledObject() { + @SuppressWarnings("unchecked") + @Deprecated + public java.rmi.MarshalledObject convertToMarshalledObject() { // To create a java.rmi.MarshalledObject with previously // serialized data we first create a private @@ -229,14 +239,14 @@ public class MarshalledInstance implemen // the class during readObject(). (See resolveClass() in // ToMOInputStream) // - net.jini.io.MarshalledObject privateMO = - new net.jini.io.MarshalledObject(); + net.jini.io.MarshalledObject privateMO = + new net.jini.io.MarshalledObject(); privateMO.objBytes = objBytes; privateMO.locBytes = locBytes; privateMO.hash = hash; - java.rmi.MarshalledObject mo = null; + java.rmi.MarshalledObject mo = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); @@ -245,7 +255,7 @@ public class MarshalledInstance implemen byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ToMOInputStream(bais); - mo = (java.rmi.MarshalledObject)ois.readObject(); + mo = (java.rmi.MarshalledObject)ois.readObject(); } catch (IOException ioe) { throw new AssertionError(ioe); } catch (ClassNotFoundException cnfe) { @@ -253,7 +263,16 @@ public class MarshalledInstance implemen } return mo; } - + + MarshalledObject asMarshalledObject(){ + MarshalledObject mo = new MarshalledObject(); + // Don't worry about defensive copies, this is package private. + mo.objBytes = objBytes; + mo.locBytes = locBytes; + mo.hash = hash; + return mo; + } + /** * Returns a new copy of the contained object. Deserialization is * performed with the semantics defined by MarshalInputStream. @@ -281,7 +300,7 @@ public class MarshalledInstance implemen * is true and the integrity of the * contained object's codebase cannot be confirmed */ - public Object get(final boolean verifyCodebaseIntegrity) + public T get(final boolean verifyCodebaseIntegrity) throws IOException, ClassNotFoundException { return get(null, verifyCodebaseIntegrity, null, null); @@ -327,7 +346,7 @@ public class MarshalledInstance implemen * is true and the integrity of the * contained object's codebase cannot be confirmed */ - public Object get(ClassLoader defaultLoader, + public T get(ClassLoader defaultLoader, final boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) @@ -355,7 +374,8 @@ public class MarshalledInstance implemen verifierLoader, context); in.useCodebaseAnnotations(); - Object obj = in.readObject(); + @SuppressWarnings("unchecked") + T obj = (T) in.readObject(); in.close(); return obj; } @@ -439,166 +459,5 @@ public class MarshalledInstance implemen */ private void readObjectNoData() throws ObjectStreamException { throw new InvalidObjectException("Bad class hierarchy"); - } - - /** - * This class is used to marshal objects for - * MarshalledInstance. It places the location annotations - * to one side so that two MarshalledInstances can be - * compared for equality if they differ only in location - * annotations. Objects written using this stream should be read back - * from a MarshalledInstanceInputStream. - * - * @see MarshalledInstanceInputStream - */ - private static class MarshalledInstanceOutputStream - extends MarshalOutputStream - { - /** The stream on which location objects are written. */ - private ObjectOutputStream locOut; - - /** true if non-null annotations are - * written. - */ - private boolean hadAnnotations; - - /** - * Creates a new MarshalledObjectOutputStream whose - * non-location bytes will be written to objOut and whose - * location annotations (if any) will be written to - * locOut. - */ - public MarshalledInstanceOutputStream(OutputStream objOut, - OutputStream locOut, - Collection context) - throws IOException - { - super(objOut, context); - this.locOut = new ObjectOutputStream(locOut); - hadAnnotations = false; - } - - /** - * Returns true if any non-null location - * annotations have been written to this stream. - */ - public boolean hadAnnotations() { - return hadAnnotations; - } - - /** - * Overrides MarshalOutputStream.writeAnnotation - * implementation to write annotations to the location stream. - */ - protected void writeAnnotation(String loc) throws IOException { - hadAnnotations |= (loc != null); - locOut.writeObject(loc); - } - - public void flush() throws IOException { - super.flush(); - locOut.flush(); - } - } - - /** - * The counterpart to MarshalledInstanceOutputStream. - * - * @see MarshalledInstanceOutputStream - */ - private static class MarshalledInstanceInputStream - extends MarshalInputStream - { - /** - * The stream from which annotations will be read. If this is - * null, then all annotations were null. - */ - private ObjectInputStream locIn; - - /** - * Creates a new MarshalledObjectInputStream that - * reads its objects from objIn and annotations - * from locIn. If locIn is - * null, then all annotations will be - * null. - */ - MarshalledInstanceInputStream(InputStream objIn, - InputStream locIn, - ClassLoader defaultLoader, - boolean verifyCodebaseIntegrity, - ClassLoader verifierLoader, - Collection context) - throws IOException - { - super(objIn, - defaultLoader, - verifyCodebaseIntegrity, - verifierLoader, - context); - this.locIn = (locIn == null ? null : new ObjectInputStream(locIn)); - } - - /** - * Overrides MarshalInputStream.readAnnotation to - * return locations from the stream we were given, or null - * if we were given a null location stream. - */ - protected String readAnnotation() - throws IOException, ClassNotFoundException - { - return (locIn == null ? null : (String)locIn.readObject()); - } } - - /** - * Input stream to convert java.rmi.MarshalledObject - * into net.jini.io.MarshalledObject. - */ - private static class FromMOInputStream extends ObjectInputStream { - - public FromMOInputStream(InputStream in) throws IOException { - super(in); - } - - /** - * Overrides ObjectInputStream.resolveClass to change - * an occurence of class java.rmi.MarshalledObject to - * class net.jini.io.MarshalledObject. - */ - protected Class resolveClass(ObjectStreamClass desc) - throws IOException, ClassNotFoundException - { - if (desc.getName().equals("java.rmi.MarshalledObject")) { - return net.jini.io.MarshalledObject.class; - } - return super.resolveClass(desc); - } - } - - /** - * Input stream to convert - * net.jini.io.MarshalledObject into - * java.rmi.MarshalledObject. - */ - private static class ToMOInputStream extends ObjectInputStream { - - public ToMOInputStream(InputStream in) throws IOException { - super(in); - } - - /** - * Overrides ObjectInputStream.resolveClass - * to change an occurence of class - * net.jini.io.MarshalledObject - * to class java.rmi.MarshalledObject. - */ - protected Class resolveClass(ObjectStreamClass desc) - throws IOException, ClassNotFoundException - { - if (desc.getName().equals("net.jini.io.MarshalledObject")) { - return java.rmi.MarshalledObject.class; - } - return super.resolveClass(desc); - } - } } Added: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceInputStream.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceInputStream.java?rev=934258&view=auto ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceInputStream.java (added) +++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceInputStream.java Thu Apr 15 01:11:12 2010 @@ -0,0 +1,38 @@ +/* + * 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 net.jini.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.util.Collection; + +class MarshalledInstanceInputStream extends MarshalInputStream { + + private ObjectInputStream locIn; + + MarshalledInstanceInputStream(InputStream objIn, InputStream locIn, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) throws IOException { + super(objIn, defaultLoader, verifyCodebaseIntegrity, verifierLoader, context); + this.locIn = (locIn == null ? null : new ObjectInputStream(locIn)); + } + + @Override + protected String readAnnotation() throws IOException, ClassNotFoundException { + return locIn == null ? null : (String) locIn.readObject(); + } +} Propchange: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceInputStream.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceOutputStream.java URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceOutputStream.java?rev=934258&view=auto ============================================================================== --- incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceOutputStream.java (added) +++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceOutputStream.java Thu Apr 15 01:11:12 2010 @@ -0,0 +1,58 @@ +/* + * 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 net.jini.io; + +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.util.Collection; + +class MarshalledInstanceOutputStream extends MarshalOutputStream { + + private ObjectOutputStream locOut; + /** true if non-null annotations are + * written. + */ + private boolean hadAnnotations; + + public MarshalledInstanceOutputStream(OutputStream objOut, OutputStream locOut, Collection context) throws IOException { + super(objOut, context); + this.locOut = new ObjectOutputStream(locOut); + hadAnnotations = false; + } + + /** + * Returns true if any non-null location + * annotations have been written to this stream. + */ + public boolean hadAnnotations() { + return hadAnnotations; + } + + @Override + protected void writeAnnotation(String loc) throws IOException { + hadAnnotations |= (loc != null); + locOut.writeObject(loc); + } + + @Override + public void flush() throws IOException { + super.flush(); + locOut.flush(); + } +} Propchange: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceOutputStream.java ------------------------------------------------------------------------------ svn:eol-style = native