    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 *
    017 */
    018package org.apache.bcel.classfile;
    019
    020import java.io.DataOutputStream;
    021import java.io.IOException;
    022
    023import org.apache.bcel.Const;
    024
    025/**
    026 * @since 6.0
    027 */
    028public class ClassElementValue extends ElementValue
    029{
    030    // For primitive types and string type, this points to the value entry in
    031    // the cpool
    032    // For 'class' this points to the class entry in the cpool
    033    private final int idx;
    034
    035    public ClassElementValue(final int type, final int idx, final ConstantPool cpool)
    036    {
    037        super(type, cpool);
    038        this.idx = idx;
    039    }
    040
    041    public int getIndex()
    042    {
    043        return idx;
    044    }
    045
    046    public String getClassString()
    047    {
    048        final ConstantUtf8 c = (ConstantUtf8) super.getConstantPool().getConstant(idx,
    049                Const.CONSTANT_Utf8);
    050        return c.getBytes();
    051    }
    052
    053    @Override
    054    public String stringifyValue()
    055    {
    056        final ConstantUtf8 cu8 = (ConstantUtf8) super.getConstantPool().getConstant(idx,
    057                Const.CONSTANT_Utf8);
    058        return cu8.getBytes();
    059    }
    060
    061    @Override
    062    public void dump(final DataOutputStream dos) throws IOException
    063    {
    064        dos.writeByte(super.getType()); // u1 kind of value
    065        dos.writeShort(idx);
    066    }
    067}