Try to resolve an object obtained from the OSGi service registry similar
to how /com.ibm.ws.jndi/ implements the default namespace.

@return the object instance, or null if an object could not be found
493070
@FFDCIgnore(NamingException.class)
    private Object resolveJNDIObject(Object o, ServiceReference<?> ref, String[] objectClass, String bindingName, Hashtable<?, ?> envmt) throws Exception {
        if ("jndi".equals(ref.getProperty("osgi.jndi.service.origin")) || contains(objectClass, Reference.class.getName())) {
            try {
                Context context = new InitialContext(envmt);
                Name name = context.getNameParser("").parse(bindingName);
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "calling NamingManager.getObjectInstance", o, name, context, envmt);
                }
                return NamingManager.getObjectInstance(o, name, context, envmt);
            } catch (NamingException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "ignoring NamingException from NamingManager.getObjectInstance", e);
                }
                return null;
            }
        }

        return o;
    }
468440
public static Object lookup(String jndiName)
    {
        if(log.isDebugEnabled()) log.debug("lookup("+jndiName+") was called");
        try
        {
            return getContext().lookup(jndiName);
        }
        catch (NamingException e)
        {
            throw new OJBRuntimeException("Lookup failed for: " + jndiName, e);
        }
        catch(OJBRuntimeException e)
        {
            throw e;
        }
    }
1332879
protected OSGiInjectionScopeData getInjectionScopeData(NamingConstants.JavaColonNamespace namespace) throws NamingException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        OSGiInjectionScopeData isd = null;

        // Get the ComponentMetaData for the currently active component.
        // There is no comp namespace if there is no active component.
        ComponentMetaData cmd = ComponentMetaDataAccessorImpl.getComponentMetaDataAccessor().getComponentMetaData();

        if (cmd == null) {
            NamingException nex = new NamingException(Tr.formatMessage(tc, "JNDI_NON_JEE_THREAD_CWNEN1000E"));
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(tc, "getInjectionScopeData : (no CMD) : " + nex.toString(true));
            throw nex;
        }

        isd = injectionEngine.getInjectionScopeData(cmd, namespace);

        if (isTraceOn && tc.isDebugEnabled())
            Tr.debug(tc, cmd + " -> " + isd);

        return isd;
    }
185880
@FFDCIgnore(PrivilegedActionException.class)
    private Object getJNDIServiceObjectInstance(final String className, final String bindingName, final Hashtable<?, ?> envmt) throws Exception {
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                @Override
                public Object run() throws Exception {
                    return getJNDIServiceObjectInstancePrivileged(className, bindingName, envmt);
                }
            });
        } catch (PrivilegedActionException paex) {
            Throwable cause = paex.getCause();
            if (cause instanceof Exception) {
                throw (Exception) cause;
            }
            throw new Error(cause);
        }
    }
1180993
protected Class resolveClass( ObjectStreamClass classDesc )throws IOException, ClassNotFoundException
  {

    String cname = classDesc.getName();
    if( cname.startsWith( "[" ) )
    {
      // An array
      Class component;    // component class
      int dcount;      // dimension
      for( dcount = 1; cname.charAt( dcount ) == '['; dcount++ )
      {
        ;
      }
      if( cname.charAt( dcount ) == 'L' )
      {
        component = loader.loadClass( cname.substring( dcount + 1,
                                                       cname.length() - 1 ) );
      }
      else
      {
        if( cname.length() != dcount + 1 )
        {
          throw new ClassNotFoundException( cname );// malformed
        }
        component = primitiveType( cname.charAt( dcount ) );
      }
      int dim[] = new int[dcount];
      for( int i = 0; i < dcount; i++ )
      {
        dim[i] = 0;
      }
      return Array.newInstance( component, dim ).getClass();
    }
    else
    {

      return loader.loadClass( cname );
    }
  }
1126324
public static IResolver defaultResolver() {
        return new IResolver() {
            @Override
            public Record[] resolve(Domain domain) throws IOException {
                String[] addresses = defaultServer();
                if (addresses == null) {
                    throw new IOException("no dns server");
                }
                IResolver resolver = new Resolver(InetAddress.getByName(addresses[0]));
                return resolver.resolve(domain);
            }
        };
    }
339161
@Override
    public ServiceReference<?> getServiceReference(String clazz) {
    	Collection<ServiceReference<?>> servrefs = serviceRegistrations.get(clazz);
    	if (servrefs == null || servrefs.size() == 0) {
            return null;
    	}

        return servrefs.iterator().next();
    }
345292
@Override
    public Service getService(URI serviceUri) throws ServiceException {
        if (serviceUri == null || !serviceUri.isAbsolute()) {
            log.warn("The Service URI is either absent or relative. Provide an absolute URI");
            return null;
        }

        OntModel model = null;
        try {
            model = this.graphStoreManager.getGraph(URIUtil.getNameSpace(serviceUri));
        } catch (URISyntaxException e) {
            log.error("The namespace of the service is not a correct URI", e);
            return null;
        }

        // Parse the service. There should only be one in the response
        ServiceReaderImpl reader = new ServiceReaderImpl();
        List<Service> services = reader.parseService(model);
        if (services != null && !services.isEmpty()) {
            return services.get(0);
        }

        return null;
    }
1152233
@Override
    public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "getObjectInstance", "" + name);
        }

        ExtendedJTATransaction extJTATran = null;

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "class name: " + (refObj instanceof Reference ? ((Reference) refObj).getClassName() : null));
        }

        extJTATran = refObj instanceof Reference && ((Reference) refObj).getFactoryClassName() == null ? createExtendedJTATransaction() : null;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "getObjectInstance: " + extJTATran);
        }

        return extJTATran;
    }
1174502
@Override
    public boolean hasObjectWithPrefix(JavaColonNamespace namespace, String name) throws NamingException {

        JavaColonNamespaceBindings<EJBBinding> bindings;
        boolean result = false;

        Lock readLock = null;
        ComponentMetaData cmd = null;

        try {
            // This helper only provides support for java:global, java:app, and java:module
            if (namespace == JavaColonNamespace.GLOBAL) {
                // Called to ensure that the java:global code path
                // is coming from a Java EE thread. If not this will reject this
                // method call with the correct Java EE error message.
                cmd = getComponentMetaData(namespace, name);
                bindings = javaColonGlobalBindings;
                readLock = javaColonLock.readLock();
                readLock.lock();

            } else if (namespace == JavaColonNamespace.APP) {
                // Get the ComponentMetaData for the currently active component.
                // There is no component name space if there is no active component.
                cmd = getComponentMetaData(namespace, name);
                bindings = getAppBindingMap(cmd.getModuleMetaData().getApplicationMetaData());

                readLock = javaColonLock.readLock();
                readLock.lock();

            } else if (namespace == JavaColonNamespace.MODULE) {
                cmd = getComponentMetaData(namespace, name);
                bindings = getModuleBindingMap(cmd.getModuleMetaData());
            } else {
                bindings = null;
            }

            result = bindings != null && bindings.hasObjectWithPrefix(name);
        } finally {
            if (readLock != null) {
                readLock.unlock();
            }
        }
        return result;
    }
381377
protected static function getResolvedClassInstance()
    {
        $classNamespace = static::getStaticClassAccessor();
        $resolvedClassInstance = self::getClass($classNamespace);
        
        if (! $resolvedClassInstance) {
            return self::resolveClassNameSpace($classNamespace);  
        }

        return $resolvedClassInstance;
    }
510257
public static ObjectModelResolver get(String resolverId) {
        List<ObjectModelResolver> resolvers = getResolvers();

        for (ObjectModelResolver resolver : resolvers) {
            if (resolver.accept(resolverId)) {
                return resolver;
            }
        }

        return null;
    }
1222480
@Override
	public Object getService(IServiceReference serviceReference) {
		final String sourceMethod = "getService"; //$NON-NLS-1$
		boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(PlatformServicesImpl.class.getName(), sourceMethod, serviceReference);
		}
		Object result = null;
		BundleContext bundleContext = Activator.getBundleContext();
		if (bundleContext != null) {
			result = bundleContext
					.getService((ServiceReference<?>) serviceReference.getPlatformObject());
		}
		if (isTraceLogging) {
			log.exiting(PlatformServicesImpl.class.getName(), sourceMethod, result);
		}
		return result;
	}
1244997
@Override
    public RemoteObjectInstance getRemoteObjectInstance(JavaColonNamespace namespace, String name) throws NamingException {
        RemoteObjectInstance roi = null;
        InjectionBinding<?> binding = getInjectionBinding(namespace, name);
        if (binding != null) {
            Object bindingObject = binding.getRemoteObject();
            if (bindingObject != null) {
                if (bindingObject instanceof IndirectReference) {
                    bindingObject = resolveIndirectReferences(binding, (IndirectReference) bindingObject, 0);
                }
                if (bindingObject instanceof javax.naming.Reference) {
                    SerializationContext sc = serializationService.createSerializationContext();
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    ObjectOutputStream oos = null;
                    try {
                        oos = sc.createObjectOutputStream(baos);
                        oos.writeObject(bindingObject);
                    } catch (IOException ex) {
                        NamingException ne = new NamingException("Unable to serialize naming reference: " + bindingObject);
                        ne.initCause(ex);
                        throw ne;
                    } finally {
                        if (oos != null)
                            try {
                                oos.close();
                            } catch (IOException ex) {
                            }
                    }
                    roi = roiFactory.create(baos.toByteArray());
                } else if (bindingObject instanceof Remote) {
                    roi = roiFactory.create((Remote) bindingObject, binding.getInjectionClassTypeName());
                } else {
                    roi = roiFactory.create(bindingObject);
                }
            }
        }
        return roi;
    }
1200890
@Override
    public final String getNamespaceURI(String prefix)
    {
        if (prefix == null) {
            throw new IllegalArgumentException(ErrorConsts.ERR_NULL_ARG);
        }
        if (prefix.length() == 0) {
            if (mDepth == 0) { // unexpected... but let's not err at this point
                /* 07-Sep-2007, TSa: Default/"no namespace" does map to
                 *    "URI" of empty String.
                 */
                return XmlConsts.DEFAULT_NAMESPACE_URI;
            }
            return mCurrElement.mDefaultNsURI;
        }
        if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
            return XMLConstants.XML_NS_URI;
        }
        if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
        }
        /* Ok, need to find the match, if any; starting from end of the
         * list of active namespaces. Note that we can not count on prefix
         * being interned/canonicalized.
         */
        return mNamespaces.findLastNonInterned(prefix);
    }
847017
public EJBHome getEJBHome() throws RemoteException
    {
        // When ivActualVersion is Constant.HOME_HANDLE_V1, ivEjbHome may
        // be null. So if this happens, we need to find the EJBHome object
        // by doing a lookup in JNDI. For all other versions, ivEjbHome
        // should never be null.
        if (ivEjbHome == null)
        {
            try
            {
                Class homeClass = null;
                try
                {
                    //
                    // If we are running on the server side, then the thread
                    // context loader would have been set appropriately by
                    // the container. If running on a client, then check the
                    // thread context class loader first
                    //
                    ClassLoader cl = Thread.currentThread().getContextClassLoader();
                    if (cl != null)
                    {
                        homeClass = cl.loadClass(ivHomeInterface);
                    }
                    else
                    {
                        throw new ClassNotFoundException();
                    }
                } catch (ClassNotFoundException ex)
                {
                    // FFDCFilter.processException(ex, CLASS_NAME + ".getEJBHome", "131", this);
                    try
                    {
                        homeClass = Class.forName(ivHomeInterface);
                    } catch (ClassNotFoundException e)
                    {
                        // FFDCFilter.processException(e, CLASS_NAME + ".getEJBHome",
                        //                             "138", this);
                        throw new ClassNotFoundException(ivHomeInterface);
                    }
                }

                InitialContext ctx = null;
                try
                {
                    // Locate the home
                    //91851 begin
                    if (this.ivInitialContextProperties == null)
                    {
                        ctx = new InitialContext();
                    }
                    else
                    {
                        try
                        {
                            ctx = new InitialContext(ivInitialContextProperties);
                        } catch (NamingException ne)
                        {
                            // FFDCFilter.processException(ne, CLASS_NAME + ".getEJBHome",
                            //                             "161", this);
                            ctx = new InitialContext();
                        }
                    }
                    //91851 end
                    ivEjbHome = (EJBHome) PortableRemoteObject.narrow(ctx.lookup(ivJndiName)
                                                                      , homeClass);
                } catch (NoInitialContextException e)
                {
                    // FFDCFilter.processException(e, CLASS_NAME + ".getEJBHome", "172", this);
                    java.util.Properties p = new java.util.Properties();
                    p.put(Context.INITIAL_CONTEXT_FACTORY
                          , "com.ibm.websphere.naming.WsnInitialContextFactory");
                    ctx = new InitialContext(p);
                    ivEjbHome = (EJBHome) PortableRemoteObject.narrow(ctx.lookup(ivJndiName)
                                                                      , homeClass);
                }
            } catch (NamingException e)
            {
                // Problem looking up the home
                // FFDCFilter.processException(e, CLASS_NAME + ".getEJBHome", "184", this);
                RemoteException re = new NoSuchObjectException("Could not find home in JNDI");
                re.detail = e;
                throw re;
            } catch (ClassNotFoundException e)
            {
                // We couldn't find the home interface's class
                // FFDCFilter.processException(e, CLASS_NAME + ".getEJBHome", "192", this);
                throw new RemoteException("Could not load home interface", e);
            }

        }

        return ivEjbHome;
    }
688024
public EObject resolveJavaObject(JvmType rootType, String fragment) throws UnknownNestedTypeException {
		if (fragment.endsWith("[]")) {
			return resolveJavaArrayObject(rootType, fragment);
		}
		int slash = fragment.indexOf('/'); 
		if (slash != -1) {
			if (slash == 0)
				return null;
			String containerFragment = fragment.substring(0, slash);
			EObject container = resolveJavaObject(rootType, containerFragment);
			if (container != null) {
				String parameterName = fragment.substring(slash + 1);
				if (container instanceof JvmTypeParameterDeclarator) {
					JvmTypeParameterDeclarator executable = (JvmTypeParameterDeclarator) container;
					for(JvmTypeParameter parameter: executable.getTypeParameters()) {
						if (parameter.getName().equals(parameterName))
							return parameter;
					}
				} 
			}
		} else {
			if (rootType.getIdentifier().equals(fragment)) {
				return rootType;
			}
			if (!fragment.startsWith(rootType.getIdentifier())) {
				return null;
			}
			int rootNameLength = rootType.getIdentifier().length();
			char sep = fragment.charAt(rootNameLength);
			Iterator<String> iter = Splitter.on(sep).split(fragment.substring(rootNameLength+1)).iterator();
			JvmDeclaredType current = (JvmDeclaredType) rootType;
			while (iter.hasNext()) {
				String segment = iter.next();
				Iterator<JvmDeclaredType> members = current.findAllNestedTypesByName(segment).iterator();
				if (members.hasNext()) {
					current = members.next();
				} else {
					throw new UnknownNestedTypeException("Couldn't resolve nested type for "+rootType.getIdentifier()+" and fragment "+fragment);
				}
			}
			return current;
		}
		return null;	
	}