code: public Object getObjectInstance(Object obj,
                                      Name name,
                                      Context nameCtx,
                                      Hashtable<?, ?> environment)
                      throws Exception
      {
          final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
          if (isTraceOn && tc.isEntryEnabled())
              Tr.entry(tc, "getObjectInstance : " + obj);
  
          // F743-17630CodRv
          // This factory should only be used from inside an ejb.
          //
          // Checking for the lack of EJBContext is good enough to tell us
          // we are not inside an ejb when the code flow was started by some
          // non-ejb component (such as a servlet).  However, in the case where
          // we've got an ejb that calls into a webservice endpoint, then there
          // may be a ContainerTx that has a BeanO, even though we are not
          // allowed to use the factory from inside the webservice endpoint.
          //
          // To account for this, we must also check the ComponentMetaData (CMD) and
          // confirm that it is ejb specific.  In the webservice endpoint case,
          // the CMD will have been switched to some non-ejb CMD, and so this check
          // so stop us.
          EJBContext ejbContext = EJSContainer.getCallbackBeanO(); // d630940
          ComponentMetaData cmd = ComponentMetaDataAccessorImpl.getComponentMetaDataAccessor().getComponentMetaData();
          if (ejbContext == null ||
              !(cmd instanceof BeanMetaData))
          {
              InjectionException iex = new InjectionException
                              ("The EJBContext type may only be injected into an EJB instance " +
                               "or looked up within the context of an EJB.");
              Tr.error(tc, "EJB_CONTEXT_DATA_NOT_AVAILABLE_CNTR0329E",
                       new Object[] { EJBContext.class.getName() });
              if (isTraceOn && tc.isEntryEnabled())
                  Tr.exit(tc, "getObjectInstance : ", iex);
              throw iex;
          }
  
          if (isTraceOn && tc.isEntryEnabled())
              Tr.exit(tc, "getObjectInstance : " + ejbContext);
  
          return ejbContext;
      }
docs: (non-Javadoc)
  
  @see ObjectFactory#getObjectInstance