Search in sources :

Example 1 with OperationAnalysis

use of org.wildfly.iiop.openjdk.rmi.OperationAnalysis in project wildfly by wildfly.

the class EjbIIOPDeploymentUnitProcessor method processEjb.

private void processEjb(final EJBComponentDescription componentDescription, final DeploymentReflectionIndex deploymentReflectionIndex, final Module module, final ServiceTarget serviceTarget, final IIOPMetaData iiopMetaData) {
    componentDescription.setExposedViaIiop(true);
    // Create bean method mappings for container invoker
    final EJBViewDescription remoteView = componentDescription.getEjbRemoteView();
    final Class<?> remoteClass;
    try {
        remoteClass = ClassLoadingUtils.loadClass(remoteView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    final EJBViewDescription homeView = componentDescription.getEjbHomeView();
    final Class<?> homeClass;
    try {
        homeClass = ClassLoadingUtils.loadClass(homeView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    componentDescription.getEjbHomeView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    componentDescription.getEjbRemoteView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    final InterfaceAnalysis remoteInterfaceAnalysis;
    try {
        // TODO: change all this to use the deployment reflection index
        remoteInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(remoteClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> beanMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] remoteAttrs = remoteInterfaceAnalysis.getAttributes();
    for (int i = 0; i < remoteAttrs.length; i++) {
        final OperationAnalysis op = remoteAttrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            // translate to the deployment reflection index method
            // TODO: this needs to be fixed so it just returns the correct method
            final Method method = translateMethod(deploymentReflectionIndex, op);
            beanMethodMap.put(op.getIDLName(), new SkeletonStrategy(method));
            final OperationAnalysis setop = remoteAttrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                // translate to the deployment reflection index method
                // TODO: this needs to be fixed so it just returns the correct method
                final Method realSetmethod = translateMethod(deploymentReflectionIndex, setop);
                beanMethodMap.put(setop.getIDLName(), new SkeletonStrategy(realSetmethod));
            }
        }
    }
    final OperationAnalysis[] ops = remoteInterfaceAnalysis.getOperations();
    for (int i = 0; i < ops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", ops[i].getJavaName(), ops[i].getIDLName());
        beanMethodMap.put(ops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, ops[i])));
    }
    // Initialize repository ids of remote interface
    final String[] beanRepositoryIds = remoteInterfaceAnalysis.getAllTypeIds();
    // Create home method mappings for container invoker
    final InterfaceAnalysis homeInterfaceAnalysis;
    try {
        // TODO: change all this to use the deployment reflection index
        homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> homeMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] attrs = homeInterfaceAnalysis.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        final OperationAnalysis op = attrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            homeMethodMap.put(op.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, op)));
            final OperationAnalysis setop = attrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                homeMethodMap.put(setop.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, setop)));
            }
        }
    }
    final OperationAnalysis[] homeops = homeInterfaceAnalysis.getOperations();
    for (int i = 0; i < homeops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", homeops[i].getJavaName(), homeops[i].getIDLName());
        homeMethodMap.put(homeops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, homeops[i])));
    }
    // Initialize repository ids of home interface
    final String[] homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
    final EjbIIOPService service = new EjbIIOPService(beanMethodMap, beanRepositoryIds, homeMethodMap, homeRepositoryIds, settingsService.isUseQualifiedName(), iiopMetaData, module);
    final ServiceBuilder<EjbIIOPService> builder = serviceTarget.addService(componentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), service);
    builder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
    builder.addDependency(homeView.getServiceName(), ComponentView.class, service.getHomeView());
    builder.addDependency(remoteView.getServiceName(), ComponentView.class, service.getRemoteView());
    builder.addDependency(CorbaORBService.SERVICE_NAME, ORB.class, service.getOrb());
    builder.addDependency(POARegistry.SERVICE_NAME, POARegistry.class, service.getPoaRegistry());
    builder.addDependency(CorbaPOAService.INTERFACE_REPOSITORY_SERVICE_NAME, POA.class, service.getIrPoa());
    builder.addDependency(CorbaNamingService.SERVICE_NAME, NamingContextExt.class, service.getCorbaNamingContext());
    builder.addDependency(IORSecConfigMetaDataService.SERVICE_NAME, IORSecurityConfigMetaData.class, service.getIORSecConfigMetaDataInjectedValue());
    builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoaderInjectedValue());
    builder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, TransactionManagerService.class, service.getTransactionManagerInjectedValue());
    builder.install();
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) HashMap(java.util.HashMap) SkeletonStrategy(org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy) Method(java.lang.reflect.Method) OperationAnalysis(org.wildfly.iiop.openjdk.rmi.OperationAnalysis) InterfaceAnalysis(org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis) AttributeAnalysis(org.wildfly.iiop.openjdk.rmi.AttributeAnalysis) RMIIIOPViolationException(org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException) EjbIIOPService(org.jboss.as.ejb3.iiop.EjbIIOPService)

Example 2 with OperationAnalysis

use of org.wildfly.iiop.openjdk.rmi.OperationAnalysis in project wildfly by wildfly.

the class IIOPStubCompiler method generateCode.

/**
 * Generates the bytecodes of a stub class for a given interface.
 *
 * @param interfaceAnalysis an <code>InterfaceAnalysis</code> instance
 *                        describing the RMI/IIOP interface to be
 *                        implemented by the stub class
 * @param superclass      the superclass of the stub class
 * @param stubClassName   the name of the stub class
 * @return a byte array with the generated bytecodes.
 */
private static ClassFile generateCode(InterfaceAnalysis interfaceAnalysis, Class<?> superclass, String stubClassName) {
    final ClassFile asm = new ClassFile(stubClassName, superclass.getName(), null, ModuleClassFactory.INSTANCE, interfaceAnalysis.getCls().getName());
    int methodIndex = 0;
    AttributeAnalysis[] attrs = interfaceAnalysis.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        OperationAnalysis op = attrs[i].getAccessorAnalysis();
        generateMethodCode(asm, superclass, op.getMethod(), op.getIDLName(), strategy(methodIndex), init(methodIndex));
        methodIndex++;
        op = attrs[i].getMutatorAnalysis();
        if (op != null) {
            generateMethodCode(asm, superclass, op.getMethod(), op.getIDLName(), strategy(methodIndex), init(methodIndex));
            methodIndex++;
        }
    }
    final OperationAnalysis[] ops = interfaceAnalysis.getOperations();
    for (int i = 0; i < ops.length; i++) {
        generateMethodCode(asm, superclass, ops[i].getMethod(), ops[i].getIDLName(), strategy(methodIndex), init(methodIndex));
        methodIndex++;
    }
    // Generate the constructor
    final ClassMethod ctor = asm.addMethod(Modifier.PUBLIC, "<init>", "V");
    ctor.getCodeAttribute().aload(0);
    ctor.getCodeAttribute().invokespecial(superclass.getName(), "<init>", "()V");
    ctor.getCodeAttribute().returnInstruction();
    // Generate the method _ids(), declared as abstract in ObjectImpl
    final String[] ids = interfaceAnalysis.getAllTypeIds();
    asm.addField(Modifier.PRIVATE + Modifier.STATIC, ID_FIELD_NAME, String[].class);
    final CodeAttribute idMethod = asm.addMethod(Modifier.PUBLIC + Modifier.FINAL, "_ids", "[Ljava/lang/String;").getCodeAttribute();
    idMethod.getstatic(stubClassName, ID_FIELD_NAME, "[Ljava/lang/String;");
    idMethod.returnInstruction();
    // Generate the static initializer
    final CodeAttribute clinit = asm.addMethod(Modifier.STATIC, "<clinit>", "V").getCodeAttribute();
    clinit.iconst(ids.length);
    clinit.anewarray(String.class.getName());
    for (int i = 0; i < ids.length; i++) {
        clinit.dup();
        clinit.iconst(i);
        clinit.ldc(ids[i]);
        clinit.aastore();
    }
    clinit.putstatic(stubClassName, ID_FIELD_NAME, "[Ljava/lang/String;");
    // last methodIndex + 1
    int n = methodIndex;
    for (methodIndex = 0; methodIndex < n; methodIndex++) {
        clinit.invokestatic(stubClassName, init(methodIndex), "()V");
    }
    clinit.returnInstruction();
    return asm;
}
Also used : ClassFile(org.jboss.classfilewriter.ClassFile) CodeAttribute(org.jboss.classfilewriter.code.CodeAttribute) AttributeAnalysis(org.wildfly.iiop.openjdk.rmi.AttributeAnalysis) ClassMethod(org.jboss.classfilewriter.ClassMethod) OperationAnalysis(org.wildfly.iiop.openjdk.rmi.OperationAnalysis)

Example 3 with OperationAnalysis

use of org.wildfly.iiop.openjdk.rmi.OperationAnalysis in project wildfly by wildfly.

the class InterfaceRepository method addOperations.

/**
 * Add a set of operations to a container (interface or value class).
 */
private void addOperations(LocalContainer container, ContainerAnalysis ca) throws RMIIIOPViolationException, IRConstructionException {
    OperationAnalysis[] ops = ca.getOperations();
    for (int i = 0; i < ops.length; ++i) {
        OperationDefImpl oDef;
        String oName = ops[i].getIDLName();
        String oid = ca.getMemberRepositoryId(oName);
        Class cls = ops[i].getReturnType();
        TypeCode typeCode = getTypeCode(cls);
        ParameterAnalysis[] ps = ops[i].getParameters();
        ParameterDescription[] params = new ParameterDescription[ps.length];
        for (int j = 0; j < ps.length; ++j) {
            params[j] = new ParameterDescription(ps[j].getIDLName(), getTypeCode(ps[j].getCls()), // filled in later
            null, ParameterMode.PARAM_IN);
        }
        ExceptionAnalysis[] exc = ops[i].getMappedExceptions();
        ExceptionDef[] exceptions = new ExceptionDef[exc.length];
        for (int j = 0; j < exc.length; ++j) {
            ExceptionDefImpl e = addException(exc[j]);
            exceptions[j] = ExceptionDefHelper.narrow(e.getReference());
        }
        oDef = new OperationDefImpl(oid, oName, "1.0", container, typeCode, params, exceptions, impl);
        container.add(oName, oDef);
    }
}
Also used : TypeCode(org.omg.CORBA.TypeCode) ExceptionAnalysis(org.wildfly.iiop.openjdk.rmi.ExceptionAnalysis) OperationAnalysis(org.wildfly.iiop.openjdk.rmi.OperationAnalysis) ParameterAnalysis(org.wildfly.iiop.openjdk.rmi.ParameterAnalysis) ExceptionDef(org.omg.CORBA.ExceptionDef) ParameterDescription(org.omg.CORBA.ParameterDescription)

Aggregations

OperationAnalysis (org.wildfly.iiop.openjdk.rmi.OperationAnalysis)3 AttributeAnalysis (org.wildfly.iiop.openjdk.rmi.AttributeAnalysis)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)1 EjbIIOPService (org.jboss.as.ejb3.iiop.EjbIIOPService)1 ClassFile (org.jboss.classfilewriter.ClassFile)1 ClassMethod (org.jboss.classfilewriter.ClassMethod)1 CodeAttribute (org.jboss.classfilewriter.code.CodeAttribute)1 ExceptionDef (org.omg.CORBA.ExceptionDef)1 ParameterDescription (org.omg.CORBA.ParameterDescription)1 TypeCode (org.omg.CORBA.TypeCode)1 ExceptionAnalysis (org.wildfly.iiop.openjdk.rmi.ExceptionAnalysis)1 InterfaceAnalysis (org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis)1 ParameterAnalysis (org.wildfly.iiop.openjdk.rmi.ParameterAnalysis)1 RMIIIOPViolationException (org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException)1 SkeletonStrategy (org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy)1