📄 gnupoa.java
字号:
if (applies(ServantRetentionPolicyValue.RETAIN)) { if (a_manager instanceof ServantActivator) servant_activator = (ServantActivator) a_manager; else throw new OBJ_ADAPTER("RETAIN requires ServantActivator", 4, CompletionStatus.COMPLETED_NO ); } else if (applies(ServantRetentionPolicyValue.NON_RETAIN)) { if (a_manager instanceof ServantLocator) servant_locator = (ServantLocator) a_manager; else throw new OBJ_ADAPTER("NON_RETAIN requires ServantLocator", 4, CompletionStatus.COMPLETED_NO ); } else throw new WrongPolicy("No servant retention policy is specified."); } /** * Get the servant manager, associated with this POA. * * @return the associated servant manager or null if it has * been previously set. * * @throws WrongPolicy if the required USE_SERVANT_MANAGER policy does not * apply to this POA. */ public ServantManager get_servant_manager() throws WrongPolicy { required(RequestProcessingPolicyValue.USE_SERVANT_MANAGER); if (servant_activator != null) return servant_activator; else return servant_locator; } /** * Get the unique Id of the POA in the process in which it is created. * This Id is needed by portable interceptors. The id is unique * for the life span of the POA in the process. For persistent * POAs, if a POA is created in the same path with the same name as * another POA, these POAs are identical have the same id. All transient * POAs are assumed unique. */ public byte[] id() { if (m_poa_id != null) return m_poa_id; else { BufferedCdrOutput buffer = new BufferedCdrOutput(); POA p = this; while (p != null) { buffer.write_string(p.the_name()); p = p.the_parent(); } m_poa_id = buffer.buffer.toByteArray(); return m_poa_id; } } /** * Returns the reference to the active object with the given Id. * * @param the_Object_Id the object id. * * @throws ObjectNotActive if there is no active object with such Id * in the scope of this POA. * @throws WrongPolicy if the required RETAIN policy does not apply to * this POA. */ public org.omg.CORBA.Object id_to_reference(byte[] the_Object_Id) throws ObjectNotActive, WrongPolicy { required(ServantRetentionPolicyValue.RETAIN); AOM.Obj ref = aom.get(the_Object_Id); if (ref == null) throw new ObjectNotActive(); else return ref.object; } /** * Returns the servant that serves the active object with the given Id. * * @param the_Object_Id the object id. * * @throws ObjectNotActive if there is no active object with such Id or * it is not currently active. * @throws WrongPolicy. This method requires either RETAIN or * USE_DEFAULT_SERVANT policies and reaises the WrongPolicy if none of them * apply to this POA. */ public Servant id_to_servant(byte[] the_Object_Id) throws ObjectNotActive, WrongPolicy { if (applies(ServantRetentionPolicyValue.RETAIN)) { AOM.Obj ref = aom.get(the_Object_Id); if (ref == null || ref.isDeactiveted()) { if (default_servant != null) return default_servant; else throw new ObjectNotActive(); } else if (ref.servant != null) return ref.servant; else if (default_servant != null) return default_servant; else throw new ObjectNotActive(); } else if (default_servant != null) { return default_servant; } else throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required."); } /** * Returns the Object Id, encapsulated in the given object reference. * * @param the_Object the object that has been previously created with this * POA. It need not be active. * * @throws WrongAdapter if the passed object is not known for this POA. * @throws WrongPolicy never (declared for the future extensions only). */ public byte[] reference_to_id(org.omg.CORBA.Object the_Object) throws WrongAdapter, WrongPolicy { AOM.Obj ref = aom.findObject(the_Object); if (ref == null) throw new WrongAdapter(); return ref.key; } /** * Returns the servant that is serving this object. * * @return if the RETAIN policy applies and the object is in the Active * Object Map, the method returns the servant, associated with this object. * Otherwise, if the USE_DEFAULT_SERVANT policy applies, the method returns * the default servant (if one was set). * * @throws ObjectNotActive if none of the conditions above are satisfied. * @throws WrongAdapter if the object reference was not created with this POA. * @throws WrongPolicy. This method requires either RETAIN or * USE_DEFAULT_SERVANT policies and reaises the WrongPolicy if none of them * apply to this POA. */ public Servant reference_to_servant(org.omg.CORBA.Object the_Object) throws ObjectNotActive, WrongPolicy, WrongAdapter { if (applies(ServantRetentionPolicyValue.RETAIN)) { AOM.Obj ref = aom.findObject(the_Object); if (ref == null) throw new WrongAdapter(); else if (ref.isDeactiveted() || ref.servant == null) { if (default_servant != null) return default_servant; else throw new ObjectNotActive(); } else return ref.servant; } else if (default_servant != null) { return default_servant; } else throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required."); } /** * Returns the id of the object, served by the given servant * (assuming that the servant serves only one object). * The id is found in one of the following ways. * <ul> * <li>If the POA has both the RETAIN and the UNIQUE_ID policy and * the specified servant is active, the method return the Object Id associated * with that servant. * </li><li> * If the POA has both the RETAIN and the IMPLICIT_ACTIVATION policy and * either the POA has the MULTIPLE_ID policy or the specified servant is * inactive, the method activates the servant using a POA-generated Object Id * and the Interface Id associated with the servant, and returns that * Object Id. * </li> * <li>If the POA has the USE_DEFAULT_SERVANT policy, the servant specified * is the default servant, and the method is being invoked in the context of * executing a request on the default servant, the method returns the * ObjectId associated with the current invocation. * </li> * </ul> * @throws ServantNotActive in all cases, not listed in the list above. * @throws WrongPolicy The method requres USE_DEFAULT_SERVANT policy or * a combination of the RETAIN policy and either the UNIQUE_ID or * IMPLICIT_ACTIVATION policies and throws the WrongPolicy if these conditions * are not satisfied. */ public byte[] servant_to_id(Servant the_Servant) throws ServantNotActive, WrongPolicy { if (applies(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT) || applies(ServantRetentionPolicyValue.RETAIN) && ( applies(IdUniquenessPolicyValue.UNIQUE_ID) || applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) ) ) { AOM.Obj ref = null; if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID)) ref = aom.findServant(the_Servant); if (ref == null && applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) ) { // Try to activate. try { return activate_object(the_Servant); } catch (ServantAlreadyActive ex) { // Either it shuld not be or the policy allows multiple ids. throw new InternalError(); } } if (ref == null) throw new ServantNotActive(); else return ref.key; } else throw new WrongPolicy("(RETAIN and UNIQUE ID) " + "or USE_DEFAULT_SERVANT required." ); } /** * <p> * Converts the given servant to the object reference. The servant will serve * all methods, invoked on the returned object. The returned object reference * can be passed to the remote client, enabling remote invocations. * </p> * <p> * If the specified servant is active, it is returned. Otherwise, if the POA * has the IMPLICIT_ACTIVATION policy the method activates the servant. In * this case, if the servant activator is set, the * {@link ServantActivatorOperations#incarnate} method will be called. * </p> * * @throws ServantNotActive if the servant is inactive and no * IMPLICIT_ACTIVATION policy applies. * @throws WrongPolicy This method needs the RETAIN policy and either the * UNIQUE_ID or IMPLICIT_ACTIVATION policies. * * @return the object, exposing the given servant in the context of this POA. */ public org.omg.CORBA.Object servant_to_reference(Servant the_Servant) throws ServantNotActive, WrongPolicy { required(ServantRetentionPolicyValue.RETAIN); AOM.Obj exists = null; if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID)) exists = aom.findServant(the_Servant); if (exists != null) { if (exists.isDeactiveted()) { if (applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)) { checkDiscarding(); exists.setDeactivated(false); incarnate(exists, exists.key, the_Servant, false); } else throw new ServantNotActive(); } else return exists.object; } if (exists == null && applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)) { checkDiscarding(); byte[] object_key = AOM.getFreeId(); ServantDelegateImpl delegate = new ServantDelegateImpl(the_Servant, this, object_key); create_and_connect(object_key, the_Servant._all_interfaces(this, object_key)[0], delegate); return delegate.object; } else throw new ServantNotActive(); } /** * Incarnate in cases when request forwarding is not expected because the * servant must be provided by the servant activator. * * @param x the aom entry, where the object is replaced by value, returned by * servant activator (if not null). * * @param key the object key. * * @param a_servant the servant that was passed as a parameter in the * activation method. * * @param use_forwarding if true, the gnuForwardRequest is throw under the * forwarding exception (for remote client). Otherwise, the request is * internally redirected (for local invocation). */ private Servant incarnate(AOM.Obj x, byte[] object_key, Servant a_servant, boolean use_forwarding ) { if (servant_activator != null) { Servant servant; try { servant = servant_activator.incarnate(object_key, this); } catch (ForwardRequest ex) { if (use_forwarding) throw new gnuForwardRequest(ex.forward_reference); else servant = ForwardedServant.create((ObjectImpl) ex.forward_reference); } if (servant != null && x != null) x.setServant(servant); if (servant == null && x != null) servant = x.servant; return servant; } else if (a_servant != null) { x.setServant(a_servant); return a_servant; } else if (x.servant != null) { return x.servant; } else if (default_servant != null) { x.setServant(default_servant); return x.servant; } else throw new BAD_INV_ORDER("No servant given and the servant activator not set"); } /** * Return the POA manager, associated with this POA. * * @return the associated POA manager (always available). */ public POAManager the_POAManager() { return m_manager; } /** * Returns the adapter activator, associated with this POA. * The newly created POA has no activator (null would be * returned). The ORB root POA also initially has no activator. * * @return tha adapter activator or null if this POA has no * associated adapter activator. */ public AdapterActivator the_activator() { return m_activator; } /** * Set the adapter activator for this POA. * * @param the activator being set. */ public void the_activator(AdapterActivator an_activator) { m_activator = an_activator; } /** * The children of this POA. * * @return the array of all childs for this POA. */ public POA[] the_children() { POA[] poas = new POA[ children.size() ]; for (int i = 0; i < poas.length; i++) { poas [ i ] = (POA) children.get(i); } return poas; } /** * Return the name of this POA. * * @return the name of POA, relative to its parent. */ public String the_name() { return name; } ; /** * Return the parent of this POA. * * @return the parent POA or <code>null</code> if this is a root POA. */ public POA the_parent() { return parent; } /** {@inheritDoc} */ public IdAssignmentPolicy create_id_assignment_policy(IdAssignmentPolicyValue a_value) { return new gnuIdAssignmentPolicy(a_value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -