1 /* 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.corba.se.impl.oa.poa ; 27 28 import java.util.Enumeration ; 29 30 import org.omg.PortableServer.POA ; 31 import org.omg.PortableServer.Servant ; 32 import org.omg.PortableServer.ServantManager ; 33 import org.omg.PortableServer.ServantLocator ; 34 import org.omg.PortableServer.ForwardRequest ; 35 import org.omg.PortableServer.POAPackage.NoServant ; 36 import org.omg.PortableServer.POAPackage.WrongPolicy ; 37 import org.omg.PortableServer.POAPackage.ObjectNotActive ; 38 import org.omg.PortableServer.POAPackage.ServantNotActive ; 39 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ; 40 import org.omg.PortableServer.POAPackage.ServantAlreadyActive ; 41 import org.omg.PortableServer.ServantLocatorPackage.CookieHolder ; 42 43 import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ; 44 import com.sun.corba.se.impl.orbutil.ORBUtility ; 45 import com.sun.corba.se.impl.orbutil.ORBConstants ; 46 47 import com.sun.corba.se.spi.oa.OAInvocationInfo ; 48 import com.sun.corba.se.impl.oa.NullServantImpl ; 49 50 /** Implementation of POARequesHandler that provides policy specific 51 * operations on the POA. 52 */ 53 public class POAPolicyMediatorImpl_NR_USM extends POAPolicyMediatorBase { 54 private ServantLocator locator ; 55 56 POAPolicyMediatorImpl_NR_USM( Policies policies, POAImpl poa ) 57 { 58 super( policies, poa ) ; 59 60 // assert !policies.retainServants() && policies.useServantManager() 61 if (policies.retainServants()) 62 throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ; 63 64 if (!policies.useServantManager()) 65 throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ; 66 67 locator = null ; 68 } 69 70 protected java.lang.Object internalGetServant( byte[] id, 71 String operation ) throws ForwardRequest 72 { 73 if (locator == null) 74 throw poa.invocationWrapper().poaNoServantManager() ; 75 76 CookieHolder cookieHolder = orb.peekInvocationInfo().getCookieHolder() ; 77 78 // Try - finally is J2EE requirement. 79 java.lang.Object servant; 80 try{ 81 poa.unlock() ; 82 83 servant = locator.preinvoke(id, poa, operation, cookieHolder); 84 if (servant == null) 85 servant = new NullServantImpl( poa.omgInvocationWrapper().nullServantReturned() ) ; 86 else 87 setDelegate( (Servant)servant, id); 88 } finally { 89 poa.lock() ; 90 } 91 92 return servant; 93 } 94 95 public void returnServant() 96 { 97 OAInvocationInfo info = orb.peekInvocationInfo(); 98 if (locator == null) 99 return; 100 101 try { 102 poa.unlock() ; 103 locator.postinvoke(info.id(), (POA)(info.oa()), 104 info.getOperation(), info.getCookieHolder().value, 105 (Servant)(info.getServantContainer()) ); 106 } finally { 107 poa.lock() ; 108 } 109 } 110 111 public void etherealizeAll() 112 { 113 // NO-OP 114 } 115 116 public void clearAOM() 117 { 118 // NO-OP 119 } 120 121 public ServantManager getServantManager() throws WrongPolicy 122 { 123 return locator ; 124 } 125 126 public void setServantManager( ServantManager servantManager ) throws WrongPolicy 127 { 128 if (locator != null) 129 throw poa.invocationWrapper().servantManagerAlreadySet() ; 130 131 if (servantManager instanceof ServantLocator) 132 locator = (ServantLocator)servantManager; 133 else 134 throw poa.invocationWrapper().servantManagerBadType() ; 135 } 136 137 public Servant getDefaultServant() throws NoServant, WrongPolicy 138 { 139 throw new WrongPolicy(); 140 } 141 142 public void setDefaultServant( Servant servant ) throws WrongPolicy 143 { 144 throw new WrongPolicy(); 145 } 146 147 public final void activateObject(byte[] id, Servant servant) 148 throws WrongPolicy, ServantAlreadyActive, ObjectAlreadyActive 149 { 150 throw new WrongPolicy(); 151 } 152 153 public Servant deactivateObject( byte[] id ) throws ObjectNotActive, WrongPolicy 154 { 155 throw new WrongPolicy(); 156 } 157 158 public byte[] servantToId( Servant servant ) throws ServantNotActive, WrongPolicy 159 { 160 throw new WrongPolicy(); 161 } 162 163 public Servant idToServant( byte[] id ) 164 throws WrongPolicy, ObjectNotActive 165 { 166 throw new WrongPolicy(); 167 } 168 }