Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.ObjectType


        AbstractMemberMetaData fields[] = cmd.getManagedMembers();
        int objectIdInstance = 2;
   
        if ((objectIdClass != null) && (objectIdClass.length() > 0))
        {
            ObjectType objectIdClassType = new ObjectType(objectIdClass);
            il.append(InstructionConstants.ALOAD_1);
            IFNE oidClassIsNotNull = new IFNE(null);
            il.append(factory.createInstanceOf(objectIdClassType));
            il.append(oidClassIsNotNull);
            createThrowException(ClassEnhancer.CN_ClassCastException, "key class is not " + objectIdClass + " or null");

            oidClassIsNotNull.setTarget(il.append(InstructionConstants.ALOAD_1));
            il.append(factory.createCast(Type.OBJECT, objectIdClassType));
            lv_o[0] = il.append(new ASTORE(objectIdInstance));

            if (fields != null)
            {
                for (int i = 0; i < fields.length; i++)
                {
                    AbstractMemberMetaData fieldConfig = (AbstractMemberMetaData)fields[i];

                    if (fieldConfig.isPrimaryKey())
                    {
                        //support for identifying relationships
                        //if the class has metadata, it is PersistenceCapable
                        //add JDOHelper.getObjectId(fieldXXXX);
                        MetaDataManager mgr = cmd.getMetaDataManager();
                        AbstractClassMetaData cmd = mgr.getMetaDataForClass(fieldConfig.getType(),
                            enhancer.getClassLoaderResolver());
                        BCELMember fieldMethod = ((BCELFieldPropertyMetaData)fieldConfig).getEnhanceField();
                        if (cmd != null && cmd.getIdentityType() != IdentityType.NONDURABLE)
                        {
                            // Identifying Relationships (PC field as primary key)
                            il.append(InstructionConstants.ALOAD_0);
                            //jdoGetPersistenceManager().getObjectById(id.field,false)
                            //  jdoGetPersistenceManager
                            il.append(InstructionConstants.ALOAD_0);
                            il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceCapable, ClassEnhancer.MN_JdoGetPersistenceManager,
                                BCELClassEnhancer.OT_PersistenceManager, Type.NO_ARGS, Constants.INVOKEINTERFACE));

                            //  getObjectById(id.field,false)
                            //  id.field

                            createGetField(
                                objectIdClass,
                                fieldConfig.getName(),
                                new ObjectType(cmd.getObjectidClass()),
                                fieldConfig.isProperty(),
                                getModifiers(objectIdClass, fieldConfig.getName()),
                                InstructionFactory.createLoad(objectIdClassType, objectIdInstance));

                            //  false
                            il.append(InstructionConstants.ICONST_0);

                            //  getObjectById
                            il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceManager, "getObjectById", Type.OBJECT,
                                new Type[]{Type.OBJECT, Type.BOOLEAN}, Constants.INVOKEINTERFACE));
                            il.append(factory.createCast(Type.OBJECT, fieldMethod.getType()));

                            createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
                        }
                        else
                        {
                            // Single Field Identity
                            if (mgr.getApiAdapter().isSingleFieldIdentityClass(objectIdClass))
                            {
                                if (Object.class.isAssignableFrom(fieldConfig.getType()) && fieldConfig.getType() != String.class)
                                {
                                    // Object wrapper type
                                    Type primitiveType = null;
                                    if (objectIdClass.equals(LongIdentity.class.getName()))
                                    {
                                        primitiveType = Type.LONG;
                                    }
                                    else if (objectIdClass.equals(CharIdentity.class.getName()))
                                    {
                                        primitiveType = Type.CHAR;
                                    }
                                    else if (objectIdClass.equals(IntIdentity.class.getName()))
                                    {
                                        primitiveType = Type.INT;
                                    }
                                    else if (objectIdClass.equals(ShortIdentity.class.getName()))
                                    {
                                        primitiveType = Type.SHORT;
                                    }
                                    else if (objectIdClass.equals(ByteIdentity.class.getName()))
                                    {
                                        primitiveType = Type.BYTE;
                                    }
                                    else if (objectIdClass.equals(StringIdentity.class.getName()))
                                    {
                                        primitiveType = Type.STRING;
                                    }
                                    else if (objectIdClass.equals(ObjectIdentity.class.getName()))
                                    {
                                        primitiveType = Type.OBJECT;
                                    }
                                    il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
                                   
                                    if (primitiveType == Type.OBJECT)
                                    {
                                        // id = (field_type)o.getKey();
                                        il.append(InstructionFactory.createLoad(Type.OBJECT, 2));
                                        il.append(factory.createInvoke(objectIdClass, "getKey", primitiveType, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
                                        il.append(factory.createCheckCast(new ObjectType(fieldConfig.getTypeName())));
                                        createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
                                    }
                                    else
                                    {
                                        // id = new Integer(o.getKey());
View Full Code Here


                    Constants.INVOKEVIRTUAL));
                il.append(new PUSH(constantPoolGen, fieldName));
                il.append(factory.createInvoke(
                    "java.lang.Class",
                    "getDeclaredField",
                    new ObjectType("java.lang.reflect.Field"),
                    new Type[] { Type.STRING },
                    Constants.INVOKEVIRTUAL));
                il.append(new ASTORE(4));
                il.append(new ALOAD(4));
                il.append(InstructionConstants.ICONST_1);
View Full Code Here

                Constants.INVOKEVIRTUAL));
            il.append(new PUSH(constantPoolGen, fieldName));
            il.append(factory.createInvoke(
                "java.lang.Class",
                "getDeclaredField",
                new ObjectType("java.lang.reflect.Field"),
                new Type[] { Type.STRING },
                Constants.INVOKEVIRTUAL));
            il.append(new ASTORE(4));
            il.append(new ALOAD(4));
            il.append(InstructionConstants.ICONST_1);
View Full Code Here

                         InstConstraintVisitor icv, ExecutionVisitor ev) {
        // build the initial frame situation for this method.
        Frame vanillaFrame = new Frame(method.getMaxLocals(), method.getMaxStack());
        if (!method.isStatic()) {
            if (method.getName().equals(Constants.CONSTRUCTOR_NAME)) {
                Frame._this = new UninitializedObjectType(new ObjectType(clazz.getClassName()));
                vanillaFrame.getLocals().set(0, new UninitializedObjectType(new ObjectType(clazz.getClassName())));
            } else {
                Frame._this = null;
                vanillaFrame.getLocals().set(0, new ObjectType(clazz.getClassName()));
            }
        }
        // fill local variables with parameter types
        Type[] argtypes = method.getArgumentTypes();
        int twoslotoffset = 0;
View Full Code Here

                    // Add frame saver and restorer for the current breakpoint

                    // determine type of object for the method invocation
                    InvokeInstruction invoke = (InvokeInstruction)ins.getInstruction();
                    Type[] arguments = invoke.getArgumentTypes(method.getConstantPool())
                    ObjectType objecttype = null;
                    if (!(invoke instanceof INVOKESTATIC)) {
                        objecttype = (ObjectType)context.getInFrame().getStack().peek(arguments.length);
                    }
                    InstructionList rList = restoreFrame(method, ins, insFactory, frame, objecttype);
                    insList.append(ins, saveFrame(method, ins, count++, insFactory, frame));
                    invokeIns.addElement(rList.getStart());
                    restorer.append(rList);
                }    
                // remove all new's               
                if (ins.getInstruction().getOpcode() == Constants.NEW) {
                    try {
                        // remove additional dup's
                        while (next != null && next.getInstruction().getOpcode() == Constants.DUP) {
                            context = cfg.contextOf(next);
                            frame = context.getOutFrame(new ArrayList());
                            InstructionHandle newnext = next.getNext();
                            insList.delete(next);
                            next = newnext;
                        }
                        InstructionTargeter[] targeter = ins.getTargeters();
                        if (targeter != null) {
                            InstructionHandle newnext = ins.getNext();
                            for (int i = 0; i < targeter.length; i++) {
                                targeter[i].updateTarget(ins, newnext);
                            }
                        }
                        insList.delete(ins);
                    } catch (TargetLostException tle) {
                        throw new ClassNotFoundException(tle.getMessage(), tle);
                    }
                } else if (ins.getInstruction().getOpcode() == Constants.INVOKESPECIAL) {
                    // duplicate stack before invokespecial to insert uninitialized object
                    frame = context.getInFrame();
                    InvokeInstruction invoke = (InvokeInstruction)ins.getInstruction();
                    Type[] arguments = invoke.getArgumentTypes(method.getConstantPool());
   
                    OperandStack os = frame.getStack();
                    Type type = os.peek(arguments.length);
                    if (type instanceof UninitializedObjectType) {
                        ObjectType objecttype = ((UninitializedObjectType) type).getInitialized();
                        InstructionList duplicator = duplicateStack(method, invoke, objecttype);
                        InstructionTargeter[] targeter = ins.getTargeters();

                        if (targeter!=null) {
                            InstructionHandle newnext = duplicator.getStart();
View Full Code Here

                }
                insList.append(insFactory.createInvoke(STACK_CLASS, getPopMethod(type), type, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
                insList.append(InstructionFactory.createStore(type, i));
            } else if (type == null) {
                insList.append(new ACONST_NULL());
                insList.append(InstructionFactory.createStore(new ObjectType("<null object>"), i));
            } else if (type instanceof UninitializedObjectType) {
                // No uninitilaized objects should be found
                // in the local variables.
            } else if (type instanceof ReferenceType) {
                insList.append(InstructionFactory.createLoad(STACK_TYPE, method.getMaxLocals()+1));
View Full Code Here

    }

    private ObjectType getObjectType(ConstantPool cp, int index) {
        ConstantCP cmr = (ConstantCP) cp.getConstant(index);
        String sig = cp.getConstantString(cmr.getClassIndex(), Constants.CONSTANT_Class);
        return new ObjectType(sig.replace('/', '.'));
    }
View Full Code Here

        } else if (clazz.isArray()) {
            return new ArrayType(translate(clazz.getComponentType()), 1);

        } else {

            return new ObjectType(clazz.getName());
        }
    }
View Full Code Here

        // A RuntimeException should not cause an
        // UndeclaredThrowableException, so we catch and re-throw it
        // that before throwable.
        if (handle_throwable_exception && handle_runtime_exception) {
            mg.addExceptionHandler(tryStart, tryEnd, rethrowLocation,
                    new ObjectType("java.lang.RuntimeException"));
        }

        // If anything else is thrown, it is wrapped in an
        // UndeclaredThrowable
        if (handle_throwable_exception) {
            InstructionHandle handlerStart = il.append(new ASTORE(1));

            il
                    .append(new NEW(
                            cp
                                    .addClass("java.lang.reflect.UndeclaredThrowableException")));
            il.append(InstructionConstants.DUP);
            il.append(new ALOAD(1));
            il.append(new INVOKESPECIAL(cp.addMethodref(
                    "java.lang.reflect.UndeclaredThrowableException", "<init>",
                    "(Ljava/lang/Throwable;)V")));

            il.append(new ATHROW());

            mg.addExceptionHandler(tryStart, tryEnd, handlerStart,
                    new ObjectType("java.lang.Throwable"));
        }

        //
        // DONE
        //
View Full Code Here

        case Constants.T_SHORT:
        case Constants.T_INT:
        case Constants.T_FLOAT:

            // float
            il.append(fac.createNew(new ObjectType(BASIC_CLASS_NAMES[tag])));

            // float Float
            il.append(InstructionConstants.DUP_X1);

            // Float float Float
            il.append(InstructionConstants.SWAP);

            // Float Float float
            il.append(fac.createInvoke(BASIC_CLASS_NAMES[tag], "<init>",
                    Type.VOID, new Type[] { type }, Constants.INVOKESPECIAL));

            // Float
            return;

        case Constants.T_DOUBLE:
        case Constants.T_LONG:

            // double/2
            il.append(fac.createNew(new ObjectType(BASIC_CLASS_NAMES[tag])));

            // double/2 Double
            il.append(InstructionConstants.DUP_X2);

            // Double double/2 Double
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.ObjectType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.