/** * <p>This is based off of code in <code>InjectionManagerImpl</code>.</p> * @return <code>JndiNameEnvironment</code> * @throws InjectionException if we're unable to obtain the * <code>JndiNameEnvironment</code> */ private JndiNameEnvironment getNamingEnvironment() throws InjectionException { ComponentInvocation inv = invokeMgr.getCurrentInvocation(); if (inv != null) { if (inv.getInvocationType()== ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION) { JndiNameEnvironment componentEnv = (JndiNameEnvironment) inv.jndiEnvironment; if (componentEnv != null) { return componentEnv; } else { throw new InjectionException("No descriptor registered for " + " current invocation : " + inv); } } else { throw new InjectionException("Wrong invocation type"); } } else { throw new InjectionException("null invocation context"); } }
LOGGER.log(Level.FINE, msg, t); InjectionException ie = new InjectionException(msg); Throwable cause = (t instanceof InvocationTargetException) ? t.getCause() : t; ie.initCause( cause ); throw ie;
public <T> void aroundInject(InjectionContext<T> injectionContext) { try { ServiceLocator serviceLocator = Globals.getDefaultHabitat(); ComponentEnvManager compEnvManager = serviceLocator.getService(ComponentEnvManager.class); JndiNameEnvironment componentEnv = compEnvManager.getCurrentJndiNameEnvironment(); Object target = injectionContext.getTarget(); String targetClass = target.getClass().getName(); if( componentEnv == null ) { //throw new IllegalStateException("No valid EE environment for injection of " + targetClass); System.err.println("No valid EE environment for injection of " + targetClass); injectionContext.proceed(); return; } injectionManager.injectInstance(target, componentEnv, false); injectionContext.proceed(); } catch(InjectionException ie) { throw new IllegalStateException(ie.getMessage(), ie); } }
} catch(InjectionException e) { logger.severe("Handler " + h.getHandlerClass() + " instance injection failed : " + e.getMessage()); continue;
public void injectInstance(Object instance, String componentId, boolean invokePostConstruct) throws InjectionException { ComponentInvocation inv = invocationMgr.getCurrentInvocation(); if( inv != null ) { JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(componentId); if( componentEnv != null ) { inject(instance.getClass(), instance, componentEnv, componentId, invokePostConstruct); } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.no-descriptor-registered-for-component", "No descriptor registered for componentId: {0}", componentId)); } } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.null-invocation-context", "Null invocation context")); } }
"Exception attempting invoke lifecycle method: {0}", lifecycleMethod); _logger.log(Level.FINE, msg, t); InjectionException ie = new InjectionException(msg); Throwable cause = (t instanceof InvocationTargetException) ? ((InvocationTargetException)t).getCause() : t; ie.initCause( cause ); throw ie;
throw new IllegalStateException(ie.getMessage(), ie);
public void injectInstance(Object instance, String componentId, boolean invokePostConstruct) throws InjectionException { ComponentInvocation inv = invocationMgr.getCurrentInvocation(); if( inv != null ) { JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(componentId); if( componentEnv != null ) { inject(instance.getClass(), instance, componentEnv, componentId, invokePostConstruct); } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.no-descriptor-registered-for-component", "No descriptor registered for componentId: {0}", componentId)); } } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.null-invocation-context", "Null invocation context")); } }
"Exception attempting invoke lifecycle method: {0}", lifecycleMethod); _logger.log(Level.FINE, msg, t); InjectionException ie = new InjectionException(msg); Throwable cause = (t instanceof InvocationTargetException) ? ((InvocationTargetException)t).getCause() : t; ie.initCause( cause ); throw ie;
public void invokeInstancePreDestroy(Object instance, boolean validate) throws InjectionException { ComponentInvocation inv = invocationMgr.getCurrentInvocation(); //if ComponentInv is null and validate is true, throw InjectionException; //if component JndiNameEnvironment is null and validate is true, throw InjectionException; //if validate is false, the above 2 null conditions are basically ignored, //except that when fine logging is enabled, fine-log a message. if( inv != null ) { JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId()); if (componentEnv != null) { invokePreDestroy(instance.getClass(), instance, componentEnv); } else if (validate || _logger.isLoggable(Level.FINE)) { String msg1 = localStrings.getLocalString( "injection-manager.no-descriptor-registered-for-invocation", "No descriptor registered for current invocation: {0}", inv); if (validate) { throw new InjectionException(msg1); } _logger.log(Level.FINE, msg1); } } else if (validate || _logger.isLoggable(Level.FINE)) { String msg2 = localStrings.getLocalString( "injection-manager.null-invocation-context", "Null invocation context"); if (validate) { throw new InjectionException(msg2); } _logger.log(Level.FINE, msg2); } }
public void injectInstance(Object instance, boolean invokePostConstruct) throws InjectionException { ComponentInvocation inv = invocationMgr.getCurrentInvocation(); if( inv != null ) { JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId()); if( componentEnv != null ) { inject(instance.getClass(), instance, componentEnv, null, invokePostConstruct); } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.no-descriptor-registered-for-invocation", "No descriptor registered for current invocation: {0}", inv)); } } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.null-invocation-context", "Null invocation context")); } }
public void injectInstance(Object instance, boolean invokePostConstruct) throws InjectionException { ComponentInvocation inv = invocationMgr.getCurrentInvocation(); if( inv != null ) { JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId()); if( componentEnv != null ) { inject(instance.getClass(), instance, componentEnv, null, invokePostConstruct); } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.no-descriptor-registered-for-invocation", "No descriptor registered for current invocation: {0}", inv)); } } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.null-invocation-context", "Null invocation context")); } }
public void invokeInstancePreDestroy(Object instance) throws InjectionException { ComponentInvocation inv = invocationMgr.getCurrentInvocation(); if( inv != null ) { JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId()); if( componentEnv != null ) { invokePreDestroy(instance.getClass(), instance, componentEnv); } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.no-descriptor-registered-for-invocation", "No descriptor registered for current invocation: {0}", inv)); } } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.null-invocation-context", "Null invocation context")); } }
public void injectClass(Class clazz, String componentId, boolean invokePostConstruct ) throws InjectionException { ComponentInvocation inv = invocationMgr.getCurrentInvocation(); if( inv != null ) { JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(componentId); if( componentEnv != null ) { injectClass(clazz, componentEnv, invokePostConstruct); } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.no-descriptor-registered-for-component", "No descriptor registered for componentId: {0}", componentId)); } } else { throw new InjectionException(localStrings.getLocalString( "injection-manager.null-invocation-context", "Null invocation context")); } }
private Method getPreDestroyMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPreDestroyMethod(); if( m == null ) { String preDestroyMethodName = injInfo.getPreDestroyMethodName(); // Check for the method within the resourceClass only. // This does not include super-classses. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PreDestroy // methods with no arguments. if( next.getName().equals(preDestroyMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPreDestroyMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.predestroy-not-found", "InjectionManager exception. PreDestroy method: {0} not found in class: {1}", injInfo.getPreDestroyMethodName(), injInfo.getClassName())); } return m; }
throw new InjectionException ("InjectionManager exception. PostConstruct method " + injInfo.getPostConstructMethodName() +
private Method getPreDestroyMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPreDestroyMethod(); if( m == null ) { String preDestroyMethodName = injInfo.getPreDestroyMethodName(); // Check for the method within the resourceClass only. // This does not include super-classses. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PreDestroy // methods with no arguments. if( next.getName().equals(preDestroyMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPreDestroyMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.predestroy-not-found", "InjectionManager exception. PreDestroy method: {0} not found in class: {1}", injInfo.getPreDestroyMethodName(), injInfo.getClassName())); } return m; }
private Method getPostConstructMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPostConstructMethod(); if( m == null ) { String postConstructMethodName = injInfo.getPostConstructMethodName(); // Check for the method within the resourceClass only. // This does not include super-classes. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PostConstruct // methods with no arguments. if( next.getName().equals(postConstructMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPostConstructMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.postconstruct-not-found", "InjectionManager exception. PostConstruct method: {0} not found in class: {1}", injInfo.getPostConstructMethodName(), injInfo.getClassName())); } return m; }
private Method getPostConstructMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPostConstructMethod(); if( m == null ) { String postConstructMethodName = injInfo.getPostConstructMethodName(); // Check for the method within the resourceClass only. // This does not include super-classes. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PostConstruct // methods with no arguments. if( next.getName().equals(postConstructMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPostConstructMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.postconstruct-not-found", "InjectionManager exception. PostConstruct method: {0} not found in class: {1}", injInfo.getPostConstructMethodName(), injInfo.getClassName())); } return m; }
throw new InjectionException(localStrings.getLocalString( "injection-manager.illegal-use-of-static-field", "Illegal use of static field on class that only supports instance-based injection: {0}", throw new InjectionException(localStrings.getLocalString( "injection-manager.appclient-injected-field-must-be-static", "Injected field: {0} on Application Client class: {1} must be declared static", throw new InjectionException(localStrings.getLocalString( "injection-manager.illegal-use-of-static-method", "Illegal use of static method on class that only supports instance-based injection: {0}", throw new InjectionException(localStrings.getLocalString( "injection-manager.appclient-injected-method-must-be-static", "Injected method: {0} on Application Client class: {1} must be declared static", next, clazz, cause.getMessage()); _logger.log(Level.FINE, msg, t); throw new InjectionException(msg, cause);