ObjectAdapterBase.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 2001, 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 */ 25package com.sun.corba.se.spi.oa ; 26 27import org.omg.PortableInterceptor.ObjectReferenceTemplate ; 28import org.omg.PortableInterceptor.ObjectReferenceFactory ; 29 30import org.omg.CORBA.Policy ; 31 32import org.omg.PortableInterceptor.ACTIVE ; 33 34import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ; 35import com.sun.corba.se.spi.ior.IORFactories ; 36import com.sun.corba.se.spi.ior.IORTemplate ; 37import com.sun.corba.se.spi.ior.ObjectAdapterId; 38import com.sun.corba.se.spi.ior.ObjectKeyTemplate ; 39import com.sun.corba.se.spi.logging.CORBALogDomains ; 40import com.sun.corba.se.spi.oa.OADestroyed ; 41import com.sun.corba.se.spi.oa.ObjectAdapter ; 42import com.sun.corba.se.spi.orb.ORB ; 43import com.sun.corba.se.spi.protocol.PIHandler ; 44 45import com.sun.corba.se.impl.logging.POASystemException ; 46import com.sun.corba.se.impl.logging.OMGSystemException ; 47import com.sun.corba.se.impl.oa.poa.Policies; 48 49abstract public class ObjectAdapterBase extends org.omg.CORBA.LocalObject 50 implements ObjectAdapter 51{ 52 private ORB orb; 53 54 // Exception wrappers 55 private final POASystemException _iorWrapper ; 56 private final POASystemException _invocationWrapper ; 57 private final POASystemException _lifecycleWrapper ; 58 private final OMGSystemException _omgInvocationWrapper ; 59 private final OMGSystemException _omgLifecycleWrapper ; 60 61 // Data related to the construction of object references and 62 // supporting the Object Reference Template. 63 private IORTemplate iortemp; 64 private byte[] adapterId ; 65 private ObjectReferenceTemplate adapterTemplate ; 66 private ObjectReferenceFactory currentFactory ; 67 68 public ObjectAdapterBase( ORB orb ) 69 { 70 this.orb = orb ; 71 _iorWrapper = POASystemException.get( orb, 72 CORBALogDomains.OA_IOR ) ; 73 _lifecycleWrapper = POASystemException.get( orb, 74 CORBALogDomains.OA_LIFECYCLE ) ; 75 _omgLifecycleWrapper = OMGSystemException.get( orb, 76 CORBALogDomains.OA_LIFECYCLE ) ; 77 _invocationWrapper = POASystemException.get( orb, 78 CORBALogDomains.OA_INVOCATION ) ; 79 _omgInvocationWrapper = OMGSystemException.get( orb, 80 CORBALogDomains.OA_INVOCATION ) ; 81 } 82 83 public final POASystemException iorWrapper() 84 { 85 return _iorWrapper ; 86 } 87 88 public final POASystemException lifecycleWrapper() 89 { 90 return _lifecycleWrapper ; 91 } 92 93 public final OMGSystemException omgLifecycleWrapper() 94 { 95 return _omgLifecycleWrapper ; 96 } 97 98 public final POASystemException invocationWrapper() 99 { 100 return _invocationWrapper ; 101 } 102 103 public final OMGSystemException omgInvocationWrapper() 104 { 105 return _omgInvocationWrapper ; 106 } 107 108 /* 109 * This creates the complete template. 110 * When it is done, reference creation can proceed. 111 */ 112 final public void initializeTemplate( ObjectKeyTemplate oktemp, 113 boolean notifyORB, Policies policies, String codebase, 114 String objectAdapterManagerId, ObjectAdapterId objectAdapterId) 115 { 116 adapterId = oktemp.getAdapterId() ; 117 118 iortemp = IORFactories.makeIORTemplate(oktemp) ; 119 120 // This calls acceptors which create profiles and may 121 // add tagged components to those profiles. 122 orb.getCorbaTransportManager().addToIORTemplate( 123 iortemp, policies, 124 codebase, objectAdapterManagerId, objectAdapterId); 125 126 adapterTemplate = IORFactories.makeObjectReferenceTemplate( orb, 127 iortemp ) ; 128 currentFactory = adapterTemplate ; 129 130 if (notifyORB) { 131 PIHandler pih = orb.getPIHandler() ; 132 if (pih != null) 133 // This runs the IORInterceptors. 134 pih.objectAdapterCreated( this ) ; 135 } 136 137 iortemp.makeImmutable() ; 138 } 139 140 final public org.omg.CORBA.Object makeObject( String repId, byte[] oid ) 141 { 142 return currentFactory.make_object( repId, oid ) ; 143 } 144 145 final public byte[] getAdapterId() 146 { 147 return adapterId ; 148 } 149 150 final public ORB getORB() 151 { 152 return orb ; 153 } 154 155 abstract public Policy getEffectivePolicy( int type ) ; 156 157 final public IORTemplate getIORTemplate() 158 { 159 return iortemp ; 160 } 161 162 abstract public int getManagerId() ; 163 164 abstract public short getState() ; 165 166 final public ObjectReferenceTemplate getAdapterTemplate() 167 { 168 return adapterTemplate ; 169 } 170 171 final public ObjectReferenceFactory getCurrentFactory() 172 { 173 return currentFactory ; 174 } 175 176 final public void setCurrentFactory( ObjectReferenceFactory factory ) 177 { 178 currentFactory = factory ; 179 } 180 181 abstract public org.omg.CORBA.Object getLocalServant( byte[] objectId ) ; 182 183 abstract public void getInvocationServant( OAInvocationInfo info ) ; 184 185 abstract public void returnServant() ; 186 187 abstract public void enter() throws OADestroyed ; 188 189 abstract public void exit() ; 190 191 abstract protected ObjectCopierFactory getObjectCopierFactory() ; 192 193 // Note that all current subclasses share the same implementation of this method, 194 // but overriding it would make sense for OAs that use a different InvocationInfo. 195 public OAInvocationInfo makeInvocationInfo( byte[] objectId ) 196 { 197 OAInvocationInfo info = new OAInvocationInfo( this, objectId ) ; 198 info.setCopierFactory( getObjectCopierFactory() ) ; 199 return info ; 200 } 201 202 abstract public String[] getInterfaces( Object servant, byte[] objectId ) ; 203} 204