poaimpl.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,329 行 · 第 1/3 页
JAVA
1,329 行
if (defaultServant == null) noServant(); return defaultServant; } /** * <code>set_servant</code> * <b>Section 3.3.8.13</b> */ public void set_servant(Servant defaultServant) throws WrongPolicy { if (!policies.useDefaultServant()) wrongPolicy(); this.defaultServant = defaultServant; setDelegate(defaultServant, "DefaultServant".getBytes()); } /** * <code>activate_object</code> * <b>Section 3.3.8.14</b> */ public synchronized byte[] activate_object(Servant servant) throws ServantAlreadyActive, WrongPolicy { if (!(policies.isSystemAssignedIds() && policies.retainServants())) wrongPolicy(); if (policies.isUniqueIds() && activeObjectMap.contains(servant)) servantAlreadyActive(); // Allocate a new system-generated object-id. byte[] id = newId(); activate(id, servant); return id; } /** * <code>activate_object_with_id</code> * <b>Section 3.3.8.15</b> */ public synchronized void activate_object_with_id(byte[] id, Servant servant) throws ObjectAlreadyActive, ServantAlreadyActive, WrongPolicy { if (!policies.retainServants()) wrongPolicy(); if (activeObjectMap.containsKey(id)) objectAlreadyActive(); if (policies.isUniqueIds() && activeObjectMap.contains(servant)) servantAlreadyActive(); activate(id, servant); } // This method is used by dispatch, where we already check for // policies before activation private final void activate(byte[] id, Servant servant) { byte[] idClone = (byte[])(id.clone()) ; setDelegate(servant, idClone ); if (orb.shutdownDebugFlag) { System.out.println("Activating object " + servant + " with POA " + this); } activeObjectMap.put(idClone, servant); if (ShutdownUtilDelegate.instance != null) { ShutdownUtilDelegate.instance.registerPOAForServant(this, servant); } } /** * <code>deactivate_object</code> * <b>3.3.8.16</b> */ public synchronized void deactivate_object(byte[] id) throws ObjectNotActive, WrongPolicy { if (!policies.retainServants()) wrongPolicy(); if (policies.useServantManager() && servantManager == null) objAdapter(MinorCodes.POA_NO_SERVANT_MANAGER, CompletionStatus.COMPLETED_NO); Servant s = activeObjectMap.get(id); if (s == null) objectNotActive(); if (orb.shutdownDebugFlag) { System.out.println("Deactivating object " + s + " with POA " + this); } // This is to make sure that TransientObjectManager releases all references //orb.disconnect(createReference(s, id)); activeObjectMap.remove(id); if (ShutdownUtilDelegate.instance != null) { ShutdownUtilDelegate.instance.unregisterPOAForServant(this, s); } boolean remaining_activations = activeObjectMap.hasMultipleIDs(s); if (servantManager != null) synchronized (servantManager) { ((ServantActivator) servantManager).etherealize( id, this, s, false, remaining_activations); } } public IOR makeTransactionalIOR( String repId, byte[] oid ) { return null ; } protected org.omg.CORBA.Object makeObjectReference( String repId, byte[] id, IORTemplate iortemp, int scid ) { ObjectImpl o = new CORBAObjectImpl(); // Create the IOR ObjectId oid = new ObjectId( id ) ; IOR ior = new IOR( orb, repId, iortemp, oid ) ; // Invoke the old proprietary object reference creation interceptor ior = orb.objectReferenceCreated( ior ) ; ClientSubcontract csub = orb.getSubcontractRegistry(). getClientSubcontract( scid ) ; csub.setOrb( orb ) ; csub.unmarshal( ior ) ; o._set_delegate( (Delegate)csub ); return o; } //Needed to be changed from private to package for DelegateImpl. protected org.omg.CORBA.Object createReference(String repId, byte[] id) { return makeObjectReference( repId, id, iortemp, scid ) ; } protected org.omg.CORBA.Object createReference(Servant servant, byte[] id) { String[] reposIds = servant._all_interfaces(this, id); return makeObjectReference( reposIds[0], id, iortemp, scid ) ; } // create a delegate and stick it in the servant. // this delegate is needed during dispatch for the ObjectImpl._orb() // method to work. private void setDelegate(Servant servant, byte[] id) { //This new servant delegate no longer needs the id for its initialization. if ( orb.delegateImpl == null ) throw new org.omg.CORBA.OBJ_ADAPTER("DelegateImpl not initialized."); servant._set_delegate(orb.delegateImpl); } /** * <code>create_reference</code> * <b>3.3.8.17</b> */ public org.omg.CORBA.Object create_reference(String repId) throws WrongPolicy { if (!policies.isSystemAssignedIds()) wrongPolicy(); return createReference(repId, newId()); } /** * <code>create_reference_with_id</code> * <b>3.3.8.18</b> */ public org.omg.CORBA.Object create_reference_with_id(byte[] oid, String repId) { // First check if a servant exists for this id if (policies.retainServants()) { Servant s = activeObjectMap.get(oid); if (s == null) return createReference(repId, oid); String[] reposIds = s._all_interfaces(this,oid); if (!repId.equals(reposIds[0])) badParam(MinorCodes.BAD_REPOSITORY_ID, CompletionStatus.COMPLETED_NO); return createReference(s, oid); } return createReference(repId, oid); } /** * <code>servant_to_id</code> * <b>3.3.8.19</b> */ public synchronized byte[] servant_to_id(Servant servant) throws ServantNotActive, WrongPolicy { if (! (policies.retainServants() && (policies.isUniqueIds() || policies.isImplicitlyActivated())) ) wrongPolicy(); if (policies.isUniqueIds() && activeObjectMap.contains(servant)) return activeObjectMap.getKey(servant); if (policies.isImplicitlyActivated() && (policies.isMultipleIds() || !activeObjectMap.contains(servant))) try { return activate_object(servant); } catch (ServantAlreadyActive s) { // XXX should not happen } servantNotActive(); return null; // to keep javac quiet } /** * <code>servant_to_reference</code> * <b>3.3.8.20</b> */ public org.omg.CORBA.Object servant_to_reference(Servant servant) throws ServantNotActive, WrongPolicy { byte[] oid = servant_to_id(servant); return createReference(servant, oid); } /** * <code>reference_to_servant</code> * <b>3.3.8.21</b> */ public synchronized Servant reference_to_servant(org.omg.CORBA.Object reference) throws ObjectNotActive, WrongPolicy, WrongAdapter { if( destroyed ) { objectNotExist(MinorCodes.ADAPTER_DESTROYED, CompletionStatus.COMPLETED_NO); } if (!policies.retainServants() && !policies.useDefaultServant()) wrongPolicy(); // reference_to_id should throw WrongAdapter // if the objref was not created by this POA byte [] id = reference_to_id(reference); if (policies.retainServants()) { Servant s = activeObjectMap.get(id); if (s != null) return s; } if (policies.useDefaultServant() && defaultServant != null) return defaultServant; objectNotActive(); return null; } /** * <code>reference_to_id</code> * <b>3.3.8.22</b> */ public synchronized byte[] reference_to_id(org.omg.CORBA.Object reference) throws WrongAdapter, WrongPolicy { if( destroyed ) { objectNotExist(MinorCodes.ADAPTER_DESTROYED, CompletionStatus.COMPLETED_NO); } // According to 99-10-07.pdf (11.3.8.23), WrongPolicy is for future // extensions // XXX: we need to be able to see if this POA was the // one that created "reference". if not, we need // to throw WrongAdapter ClientSC clientSC = (ClientSC) ((ObjectImpl) reference)._get_delegate(); // check if the poaId in the reference matches the Id for this POA // if not then WrongAdapter Exception is thrown if (!clientSC.getPOAId().equals( poaId )) wrongAdapter(); return clientSC.getObjectId(); } /** * <code>id_to_servant</code> * <b>3.3.8.23</b> */ public synchronized Servant id_to_servant(byte[] id) throws ObjectNotActive, WrongPolicy { if( destroyed ) { objectNotExist(MinorCodes.ADAPTER_DESTROYED, CompletionStatus.COMPLETED_NO); } if (!policies.retainServants()) wrongPolicy(); Servant s = activeObjectMap.get(id); if (s == null) objectNotActive(); return s; } /** * <code>id_to_reference</code> * <b>3.3.8.24</b> */ public synchronized org.omg.CORBA.Object id_to_reference(byte[] id) throws ObjectNotActive, WrongPolicy { if( destroyed ) { objectNotExist(MinorCodes.ADAPTER_DESTROYED, CompletionStatus.COMPLETED_NO); } if (!policies.retainServants()) wrongPolicy(); Servant s = activeObjectMap.get(id); if (s == null) objectNotActive(); return createReference(s, id); } /** * <code>id</code> * <b>11.3.8.26 in ptc/00-08-06</b> */ public byte[] id() { return adapterId ; } private byte[] newId() { byte[] array = new byte[4]; synchronized (sysIdCounter) { int value = sysIdCounter.intValue(); ORBUtility.intToBytes(value, array, 0); sysIdCounter = new Integer(++value); } return array; } // Errors static final void wrongPolicy() throws WrongPolicy { throw new WrongPolicy(); } static final void wrongAdapter() throws WrongAdapter { throw new WrongAdapter(); } static final void adapterAlreadyExists() throws AdapterAlreadyExists { throw new AdapterAlreadyExists(); } static final void adapterNonExistent() throws AdapterNonExistent { throw new AdapterNonExistent(); } static final void noServant() throws NoServant { throw new NoServant(); } static final void servantAlreadyActive() throws ServantAlreadyActive { throw new ServantAlreadyActive(); } static final void servantNotActive() throws ServantNotActive { throw new ServantNotActive(); } static final void objectAlreadyActive() throws ObjectAlreadyActive { throw new ObjectAlreadyActive(); } static final void objectNotActive() throws ObjectNotActive { throw new ObjectNotActive(); } static final void objectNotExist(int minor, CompletionStatus status) throws OBJECT_NOT_EXIST { throw new OBJECT_NOT_EXIST(minor, status); } static final void objAdapter(int minor, CompletionStatus status) throws OBJ_ADAPTER { throw new OBJ_ADAPTER(minor, status); } static final void badParam(int minor, CompletionStatus status) throws BAD_PARAM { throw new org.omg.CORBA.BAD_PARAM(MinorCodes.BAD_REPOSITORY_ID, CompletionStatus.COMPLETED_NO); } static final void debug(String s) { System.out.println(s); } public IORTemplate getIORTemplate() { return iortemp ; } // Note: This method is made public so it can be accessed by the // Portable Interceptors package. This should not be a security risk // since any decisions that can be made based on these policies will // have been made long before any untrusted code can call this method. public Policy get_effective_policy( int type ) { return policies.get_effective_policy( type ) ; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?