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 */
017package org.apache.commons.compress.harmony.unpack200.bytecode;
018
019import java.io.DataOutputStream;
020import java.io.IOException;
021
022/**
023 * The abstract superclass for all types of class file entries.
024 */
025public abstract class ClassFileEntry {
026
027    protected static final ClassFileEntry[] NONE = {};
028    private boolean resolved;
029
030    protected abstract void doWrite(DataOutputStream dos) throws IOException;
031
032    @Override
033    public abstract boolean equals(Object arg0);
034
035    protected ClassFileEntry[] getNestedClassFileEntries() {
036        return NONE;
037    }
038
039    @Override
040    public abstract int hashCode();
041
042    protected int objectHashCode() {
043        return super.hashCode();
044    }
045
046    /**
047     * Allows the constant pool entries to resolve their nested entries.
048     *
049     * @param pool TODO
050     */
051    protected void resolve(final ClassConstantPool pool) {
052        resolved = true;
053    }
054
055    @Override
056    public abstract String toString();
057
058    public final void write(final DataOutputStream dos) throws IOException {
059        if (!resolved) {
060            throw new IllegalStateException("Entry has not been resolved");
061        }
062        doWrite(dos);
063    }
064
065}