Search in sources :

Example 16 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class StatefulComponentDescription method addViewSerializationInterceptor.

private void addViewSerializationInterceptor(final ViewDescription view) {
    view.setSerializable(true);
    view.setUseWriteReplace(true);
    view.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            final DeploymentReflectionIndex index = context.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
            ClassReflectionIndex classIndex = index.getClassIndex(WriteReplaceInterface.class);
            for (Method method : (Collection<Method>) classIndex.getMethods()) {
                configuration.addClientInterceptor(method, new StatefulWriteReplaceInterceptor.Factory(configuration.getViewServiceName().getCanonicalName()), InterceptorOrder.Client.WRITE_REPLACE);
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ComponentInstanceInterceptorFactory(org.jboss.as.ee.component.ComponentInstanceInterceptorFactory) Method(java.lang.reflect.Method) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 17 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class MethodAnnotationAggregator method runtimeAnnotationInformation.

public static <A extends Annotation, T> RuntimeAnnotationInformation<T> runtimeAnnotationInformation(final Class<?> componentClass, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex index, final Class<A> annotationType) {
    final HashSet<MethodIdentifier> methodIdentifiers = new HashSet<MethodIdentifier>();
    final Map<Method, List<T>> methods = new HashMap<Method, List<T>>();
    final Map<String, List<T>> classAnnotations = new HashMap<String, List<T>>();
    Class<?> c = componentClass;
    while (c != null && c != Object.class) {
        final ClassReflectionIndex classIndex = index.getClassIndex(c);
        final EEModuleClassDescription description = applicationClasses.getClassByName(c.getName());
        if (description != null) {
            ClassAnnotationInformation<A, T> annotationData = description.getAnnotationInformation(annotationType);
            if (annotationData != null) {
                if (!annotationData.getClassLevelAnnotations().isEmpty()) {
                    classAnnotations.put(c.getName(), annotationData.getClassLevelAnnotations());
                }
                for (Map.Entry<MethodIdentifier, List<T>> entry : annotationData.getMethodLevelAnnotations().entrySet()) {
                    final Method method = classIndex.getMethod(entry.getKey());
                    if (method != null) {
                        //we do not have to worry about private methods being overridden
                        if (Modifier.isPrivate(method.getModifiers()) || !methodIdentifiers.contains(entry.getKey())) {
                            methods.put(method, entry.getValue());
                        }
                    } else {
                        //but if it does, we give some info
                        throw EeLogger.ROOT_LOGGER.cannotResolveMethod(entry.getKey(), c, entry.getValue());
                    }
                }
            }
        }
        //so we can check if a method is overriden
        for (Method method : (Iterable<Method>) classIndex.getMethods()) {
            //we do not have to worry about private methods being overridden
            if (!Modifier.isPrivate(method.getModifiers())) {
                methodIdentifiers.add(MethodIdentifier.getIdentifierForMethod(method));
            }
        }
        c = c.getSuperclass();
    }
    return new RuntimeAnnotationInformation<T>(classAnnotations, methods);
}
Also used : HashMap(java.util.HashMap) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) List(java.util.List) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 18 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class ReflectionUtils method getGetter.

static Method getGetter(final List<ClassReflectionIndex> classHierarchy, final String propertyName) {
    final String getterName = "get" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
    final String iserName = "is" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
    for (final ClassReflectionIndex classIndex : classHierarchy) {
        final Iterator<Method> methods = classIndex.getMethods().iterator();
        Method method = null;
        String methodName = null;
        while (methods.hasNext()) {
            method = methods.next();
            methodName = method.getName();
            if ((getterName.equals(methodName) || iserName.equals(methodName)) && method.getParameterTypes().length == 0) {
                return method;
            }
        }
    }
    final String className = classHierarchy.get(0).getIndexedClass().getName();
    throw SarLogger.ROOT_LOGGER.propertyMethodNotFound("Get", propertyName, className);
}
Also used : ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) Method(java.lang.reflect.Method)

Example 19 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class ApplicationClientStartProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final ApplicationClientMetaData appClientData = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA);
    final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    //setup the callback handler
    final CallbackHandler callbackHandler;
    if (appClientData != null && appClientData.getCallbackHandler() != null && !appClientData.getCallbackHandler().isEmpty()) {
        try {
            final Class<?> callbackClass = ClassLoadingUtils.loadClass(appClientData.getCallbackHandler(), module);
            callbackHandler = new RealmCallbackWrapper((CallbackHandler) callbackClass.newInstance());
        } catch (ClassNotFoundException e) {
            throw AppClientLogger.ROOT_LOGGER.couldNotLoadCallbackClass(appClientData.getCallbackHandler());
        } catch (Exception e) {
            throw AppClientLogger.ROOT_LOGGER.couldNotCreateCallbackHandler(appClientData.getCallbackHandler());
        }
    } else {
        callbackHandler = new DefaultApplicationClientCallbackHandler();
    }
    Boolean activate = deploymentUnit.getAttachment(AppClientAttachments.START_APP_CLIENT);
    if (activate == null || !activate) {
        return;
    }
    final Class<?> mainClass = deploymentUnit.getAttachment(AppClientAttachments.MAIN_CLASS);
    if (mainClass == null) {
        throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName());
    }
    final ApplicationClientComponentDescription component = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT);
    Method mainMethod = null;
    Class<?> klass = mainClass;
    while (klass != Object.class) {
        final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(klass);
        mainMethod = index.getMethod(void.class, "main", String[].class);
        if (mainMethod != null) {
            break;
        }
        klass = klass.getSuperclass();
    }
    if (mainMethod == null) {
        throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName(), mainClass);
    }
    final ApplicationClientStartService startService;
    final List<SetupAction> setupActions = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.OTHER_EE_SETUP_ACTIONS);
    if (connectionPropertiesUrl != null) {
        try {
            final File file = new File(connectionPropertiesUrl);
            final URL url;
            if (file.exists()) {
                url = file.toURI().toURL();
            } else {
                url = new URL(connectionPropertiesUrl);
            }
            Properties properties = new Properties();
            InputStream stream = null;
            try {
                stream = url.openStream();
                properties.load(stream);
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException e) {
                    //ignore
                    }
                }
            }
            final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
                startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
            }
        } catch (Exception e) {
            throw AppClientLogger.ROOT_LOGGER.exceptionLoadingEjbClientPropertiesURL(connectionPropertiesUrl, e);
        }
    } else {
        startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions, hostUrl, callbackHandler);
    }
    phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ApplicationClientStartService.SERVICE_NAME), startService).addDependency(ApplicationClientDeploymentService.SERVICE_NAME, ApplicationClientDeploymentService.class, startService.getApplicationClientDeploymentServiceInjectedValue()).addDependency(component.getCreateServiceName(), Component.class, startService.getApplicationClientComponent()).install();
}
Also used : DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) Properties(java.util.Properties) URL(java.net.URL) RealmCallbackWrapper(org.jboss.as.appclient.service.RealmCallbackWrapper) ApplicationClientComponentDescription(org.jboss.as.appclient.component.ApplicationClientComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Component(org.jboss.as.ee.component.Component) InputStream(java.io.InputStream) DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) SetupAction(org.jboss.as.server.deployment.SetupAction) Method(java.lang.reflect.Method) IOException(java.io.IOException) ApplicationClientStartService(org.jboss.as.appclient.service.ApplicationClientStartService) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) File(java.io.File)

Example 20 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class DefaultBeanInfo method getGetter.

@Override
public Method getGetter(final String propertyName, final Class<?> type) {
    final boolean isBoolean = Boolean.TYPE.equals(type);
    final String name = ((isBoolean) ? "is" : "get") + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
    final Method result = lookup(new Lookup<Method>() {

        @Override
        public Method lookup(ClassReflectionIndex index) {
            Collection<Method> methods = index.getAllMethods(name, 0);
            if (type == null) {
                if (methods.size() == 1)
                    return methods.iterator().next();
                else
                    return null;
            }
            for (Method m : methods) {
                Class<?> pt = m.getReturnType();
                if (pt.isAssignableFrom(type))
                    return m;
            }
            return null;
        }
    }, 0, Integer.MAX_VALUE);
    if (result == null)
        throw PojoLogger.ROOT_LOGGER.getterNotFound(type, beanClass.getName());
    return result;
}
Also used : ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) Collection(java.util.Collection) Method(java.lang.reflect.Method)

Aggregations

ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)29 Method (java.lang.reflect.Method)24 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)11 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)8 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)5 ViewDescription (org.jboss.as.ee.component.ViewDescription)5 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)5 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)5 Module (org.jboss.modules.Module)5 ArrayList (java.util.ArrayList)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)4 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)4 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)4 WriteReplaceInterface (org.jboss.as.ee.component.serialization.WriteReplaceInterface)4 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)4 Map (java.util.Map)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3