Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.ObjectType


        {
            return Type.SHORT;
        }
        else
        {
            return new ObjectType(typeName);
        }
    }
View Full Code Here


     */
    public static ObjectType getPrimitiveWrapperType(BasicType bt)
    {
        if (bt.equals(Type.BOOLEAN))
        {
            return new ObjectType(Boolean.class.getName());
        }
        else if (bt.equals(Type.BYTE))
        {
            return new ObjectType(Byte.class.getName());
        }
        else if (bt.equals(Type.DOUBLE))
        {
            return new ObjectType(Double.class.getName());
        }
        else if (bt.equals(Type.FLOAT))
        {
            return new ObjectType(Float.class.getName());
        }
        else if (bt.equals(Type.INT))
        {
            return new ObjectType(Integer.class.getName());
        }
        else if (bt.equals(Type.LONG))
        {
            return new ObjectType(Long.class.getName());
        }
        else if (bt.equals(Type.SHORT))
        {
            return new ObjectType(Short.class.getName());
        }
        else if (bt.equals(Type.CHAR))
        {
            return new ObjectType(Character.class.getName());
        }

        return new ObjectType("java.lang.Object");
    }
View Full Code Here

        // We have no fields so pass up to superclass if possible
        if ((targetFields == null) || (targetFields.length == 0))
        {
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
                ObjectType pcscType = new ObjectType(cmd.getPersistenceCapableSuperclass());
                il.append(InstructionConstants.ALOAD_0);
                il.append(InstructionConstants.ALOAD_1);
                il.append(InstructionConstants.ILOAD_2);
                il.append(factory.createInvoke(
                    cmd.getPersistenceCapableSuperclass(),
                    methodGen.getName(),
                    Type.VOID,
                    new Type[] { pcscType, Type.INT },
                    Constants.INVOKESPECIAL));
            }
            il.append(InstructionConstants.RETURN);
            return;
        }

        // Create "switch" statement to handle our own fields here, and pass
        // all others up to superclasses
        InstructionHandle swichBlock;
        InstructionHandle switchTable[] = new InstructionHandle[targetFields.length];
        InstructionHandle swichDefaultBlock;
        InstructionHandle last;
        BranchInstruction gotoLast[] = new BranchInstruction[targetFields.length];
        int fieldIndexes[] = new int[targetFields.length];
        for (int i = 0; i < targetFields.length; i++)
        {
            fieldIndexes[i] = i;
        }
        il.append(InstructionConstants.ILOAD_2);
        if (cmd.getPersistenceCapableSuperclass() != null)
        {
            il.append(
                factory.createGetStatic(className, ClassEnhancer.FN_JdoInheritedFieldCount, Type.INT));
            il.append(InstructionConstants.ISUB);
        }
        swichBlock = il.append(InstructionConstants.NOP);
        for (int i = 0; i < targetFields.length; i++)
        {
            switchTable[i] = il.append(InstructionConstants.ALOAD_0);
            il.append(InstructionConstants.ALOAD_1);
            BCELMember field = ((BCELFieldPropertyMetaData)targetFields[i]).getEnhanceField();
            if (!targetFields[i].isProperty())
            {
                // fieldName = obj.fieldName
                il.append(
                    factory.createGetField(
                        className,
                        targetFields[i].getName(),
                        field.getType()));
                il.append(
                    factory.createPutField(
                        className,
                        targetFields[i].getName(),
                        field.getType()));
            }
            else
            {
                //setFieldName(obj.getFieldName());
               
                String fieldName = ClassUtils.getFieldNameForJavaBeanGetter(field.getName());
                il.append(factory.createInvoke(
                    className,
                    "jdo"+BCELUtils.getGetterName(fieldName),
                    field.getType(),
                    new Type[] {},
                    Constants.INVOKEVIRTUAL));

                il.append(factory.createInvoke(
                    className,
                    "jdo"+BCELUtils.getSetterName(fieldName),
                    Type.VOID,
                    new Type[] { field.getType() },
                    Constants.INVOKEVIRTUAL));
            }
            gotoLast[i] = new GOTO(null);
            il.append(gotoLast[i]);
        }
        if (cmd.getPersistenceCapableSuperclass() == null)
        {
            swichDefaultBlock =
                createThrowException(
                    ClassEnhancer.CN_IllegalArgumentException,
                    "out of field index :",
                    InstructionConstants.ILOAD_2);
        }
        else
        {
            ObjectType pcscType = new ObjectType(cmd.getPersistenceCapableSuperclass());
            swichDefaultBlock = il.append(InstructionConstants.ALOAD_0);
            il.append(InstructionConstants.ALOAD_1);
            il.append(InstructionConstants.ILOAD_2);
            il.append(
                factory.createInvoke(
View Full Code Here

        InstructionHandle lv_o[] = new InstructionHandle[2];

        String oidClassName = cmd.getObjectidClass();
        if ((oidClassName != null) && (oidClassName.length() > 0))
        {
            ObjectType oidType = new ObjectType(oidClassName);
            il.append(InstructionConstants.ALOAD_1);
            BranchInstruction checkFmNotNull = new IFNONNULL(null);
            il.append(checkFmNotNull);
            createThrowException(ClassEnhancer.CN_IllegalArgumentException, "ObjectIdFieldConsumer is null");
            checkFmNotNull.setTarget(il.append(InstructionConstants.ALOAD_2));
            il.append(factory.createInstanceOf(oidType));

            BranchInstruction isInstanceof = new IFNE(null);
            il.append(isInstanceof);
            createThrowException(ClassEnhancer.CN_ClassCastException, "oid is not instanceof " + oidClassName);

            isInstanceof.setTarget(il.append(InstructionConstants.ALOAD_2));
            il.append(factory.createCast(Type.OBJECT, oidType));
            lv_o[0] = il.append(new ASTORE(3));

            if (fields != null)
            {
                for (int i = 0; i < fields.length; i++)
                {
                    AbstractMemberMetaData fieldConfig = (AbstractMemberMetaData)fields[i];
                    if (fieldConfig.isPrimaryKey())
                    {
                        BCELMember field = ((BCELFieldPropertyMetaData)targetFields[i]).getEnhanceField();

                        il.append(InstructionConstants.ALOAD_1);
                        il.append(BCELUtils.getBIPUSH(i));

                        //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());
                        if (cmd != null && cmd.getIdentityType() != IdentityType.NONDURABLE)
                        {
                            //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(
                                oidClassName,
                                fieldConfig.getName(),
                                new ObjectType(cmd.getObjectidClass()),
                                fieldConfig.isProperty(),
                                getModifiers(oidClassName, fieldConfig.getName()),
                                new ALOAD(3));

                            //  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, ((BCELFieldPropertyMetaData)fieldConfig).getEnhanceField().getType()));
                        }
                        else
                        {
                            if (mgr.getApiAdapter().isSingleFieldIdentityClass(oidClassName))
                            {
                                Type getKeyReturnType = field.getType();
                                if (oidClassName.equals(LongIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.LONG;
                                }
                                else if (oidClassName.equals(CharIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.CHAR;
                                }
                                else if (oidClassName.equals(ByteIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.BYTE;
                                }
                                else if (oidClassName.equals(IntIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.INT;
                                }
                                else if (oidClassName.equals(ShortIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.SHORT;
                                }
                                else if (oidClassName.equals(StringIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.STRING;
                                }
                                else if (oidClassName.equals(ObjectIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.OBJECT;
                                }

                                if (!getKeyReturnType.equals(field.getType()))
                                {
                                    if (getKeyReturnType == Type.OBJECT)
                                    {
                                        // Return type from getKey() needs cast to correct object type
                                        il.append(InstructionFactory.createLoad(Type.OBJECT, 3));
                                        il.append(factory.createInvoke(oidClassName, "getKey", getKeyReturnType, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
                                        il.append(factory.createCheckCast(new ObjectType(fieldConfig.getTypeName())));
                                    }
                                    else
                                    {
                                        // Return type from getKey() needs conversion to object wrapper
                                        il.append(factory.createNew(fieldConfig.getTypeName()));
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

                "clone",
                Type.OBJECT,
                Type.NO_ARGS,
                Constants.INVOKESPECIAL));
       
        il.append(factory.createCast(Type.OBJECT, new ObjectType(getClassEnhancer().className)));
        lvClonedInstance[0] = il.append(InstructionConstants.ASTORE_1);
        il.append(InstructionConstants.ALOAD_1);
        il.append(InstructionConstants.ICONST_0);
        il.append(factory.createPutField(getClassEnhancer().className, ClassEnhancer.FN_Flag, Type.BYTE));
        il.append(InstructionConstants.ALOAD_1);
        il.append(InstructionConstants.ACONST_NULL);
        il.append(
            factory.createPutField(getClassEnhancer().className, ClassEnhancer.FN_StateManager, BCELClassEnhancer.OT_StateManager));
        il.append(InstructionConstants.ALOAD_1);
        lvClonedInstance[1] = il.append(InstructionConstants.ARETURN);
        methodGen.addLocalVariable(
            "o",
            new ObjectType(getClassEnhancer().className),
            lvClonedInstance[0],
            lvClonedInstance[1]);
        methodGen.addException(CloneNotSupportedException.class.getName());
    }
View Full Code Here

            //the below is dead code, verifier does not like it
            //il.append(InstructionConstants.RETURN);
        }
        else 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 f = (AbstractMemberMetaData)fields[i];
                    BCELMember fieldMethod = ((BCELFieldPropertyMetaData)f).getEnhanceField();
                   
                    if (f.isPrimaryKey())
                    {
                        createPathField(
                                f.getName(),
                                f.isProperty(),
                                getModifiers(objectIdClass, f.getName()),
                                InstructionFactory.createLoad(objectIdClassType, objectIdInstance));
                        //il.append(InstructionFactory.createLoad(objectIdClassType, objectIdInstance));
                        il.append(InstructionConstants.ALOAD_0);
                        createGetField(f.getName(), fieldMethod.getType(), f.isProperty());
                        //support for identifying relationships
                        //if the class has metadata, it is PersistenceCapable
                        //add JDOHelper.getObjectId(fieldXXXX);
                        MetaDataManager mgr = cmd.getMetaDataManager();
                        AbstractClassMetaData cmd = mgr.getMetaDataForClass(f.getType(),
                            enhancer.getClassLoaderResolver());
                        if (cmd != null)
                        {
                            il.append(
                                factory.createInvoke(
                                    ClassEnhancer.CN_JDOHelper,
                                    "getObjectId",
                                    Type.OBJECT,
                                    new Type[] { Type.OBJECT },
                                    Constants.INVOKESTATIC));
                       
                            ObjectType OT_objectidclass = new ObjectType(cmd.getObjectidClass());
                            il.append(factory.createCast(Type.OBJECT, OT_objectidclass));
                            createPutField(
                                objectIdClass,
                                f.getName(),
                                OT_objectidclass,
View Full Code Here

            //il.append(InstructionConstants.RETURN);
        }
        else if ((oidClassName != null) && (oidClassName.length() > 0))
        {
            AbstractMemberMetaData targetFields[] = cmd.getManagedMembers();
            ObjectType oidType = new ObjectType(oidClassName);
            il.append(InstructionConstants.ALOAD_1);
            BranchInstruction checkFmNotNull = new IFNONNULL(null);
            il.append(checkFmNotNull);
            createThrowException(ClassEnhancer.CN_IllegalArgumentException, "ObjectIdFieldSupplier is null");
            checkFmNotNull.setTarget(il.append(InstructionConstants.ALOAD_2));
            il.append(factory.createInstanceOf(oidType));
            il.append(InstructionConstants.ICONST_1);
            BranchInstruction isInstanceof = new IF_ICMPEQ(null);
            il.append(isInstanceof);
            createThrowException(
                ClassEnhancer.CN_ClassCastException,
                "oid is not instanceof " + oidClassName);

            isInstanceof.setTarget(il.append(InstructionConstants.ALOAD_2));
            il.append(factory.createCast(Type.OBJECT, oidType));
            lv_o[0] = il.append(new ASTORE(3));

            if (fields != null)
            {
                for (int i=0; i<fields.length; i++)
                {
                    AbstractMemberMetaData f = (AbstractMemberMetaData)fields[i];
                    BCELMember fieldMethod = ((BCELFieldPropertyMetaData)f).getEnhanceField();
                    if (f.isPrimaryKey())
                    {
                        createPathField(
                            f.getName(),
                            f.isProperty(),
                            getModifiers(oidClassName, f.getName()),
                            InstructionFactory.createLoad(oidType, 3));
                        BCELMember field = ((BCELFieldPropertyMetaData)targetFields[i]).getEnhanceField();
                        il.append(InstructionConstants.ALOAD_1);
                        il.append(BCELUtils.getBIPUSH(i));
                        String paramName = BCELUtils.getJDOMethodName(field.getType());
                        il.append(
                            factory.createInvoke(
                                ClassEnhancer.CN_ObjectIdFieldSupplier,
                                "fetch" + paramName + "Field",
                                BCELUtils.getJDOMethodType(field.getType()),
                                new Type[] { Type.INT },
                                Constants.INVOKEINTERFACE));
                        if (BCELUtils.getJDOMethodType(field.getType()) == Type.OBJECT)
                        {
                            String type = null;
                            if (field.getType() instanceof ArrayType)
                                type = field.getType().getSignature();
                            else
                                type = field.getType().toString();
                            il.append(new CHECKCAST(constantPoolGen.addClass(type)));
                        }

                        //support for identifying relationships
                        //if the class has metadata, it is PersistenceCapable
                        //add JDOHelper.getObjectId(fieldXXXX);
                        MetaDataManager mgr = cmd.getMetaDataManager();
                        AbstractClassMetaData cmd = mgr.getMetaDataForClass(f.getType(), enhancer.getClassLoaderResolver());
                        if (cmd != null)
                        {
                            il.append(
                                factory.createInvoke(
                                    ClassEnhancer.CN_JDOHelper,
                                    "getObjectId",
                                    Type.OBJECT,
                                    new Type[] { Type.OBJECT },
                                    Constants.INVOKESTATIC));
                       
                            ObjectType OT_objectidclass = new ObjectType(cmd.getObjectidClass());
                            il.append(factory.createCast(Type.OBJECT, OT_objectidclass));
                            createPutField(
                                oidClassName,
                                f.getName(),
                                OT_objectidclass,
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

    {
        return new WriteObject(
            "writeObject",
            Constants.ACC_PRIVATE | Constants.ACC_FINAL,
            Type.VOID,
            new Type[] { new ObjectType(CN_ObjectOutputStreamName)},
            new String[] { "out" },
            true,
            gen);
    }
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.