Johannes Koch schrieb:
But I would like to have one object wrapping the dictionary (giving protected access via getCOSDictionary()), so more specific PD objects could extend it.

Any more thoughts on this?

What is the benefit of having so many classes implement the getCOSDIctionary() method on their own?

Why not have one class providing this functionality?

public class PDDictionaryWrapper implements COSObjectable
{

    private final COSDictionary dictionary;

    /**
     * Default constructor
     */
    public PDDictionaryWrapper()
    {
        this.dictionary = new COSDictionary();
    }

    /**
     *
     * @param dictionary the dictionary
     */
    public PDDictionaryWrapper(COSDictionary dictionary)
    {
        this.dictionary = dictionary;
    }


    public COSBase getCOSObject()
    {
        return this.dictionary;
    }

    /**
     * Returns the dictionary.
     *
     * @return the dictionary
     */
    protected COSDictionary getCOSDictionary()
    {
        return this.dictionary;
    }


    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj instanceof PDDictionaryWrapper)
        {
return this.dictionary.equals(((PDDictionaryWrapper) obj).dictionary);
        }
        return false;
    }

    @Override
    public int hashCode()
    {
        return this.dictionary.hashCode();
    }

}

and for objects with a required Type:

public class PDTypedDictionaryWrapper extends PDDictionaryWrapper
{

    /**
     *
     * @param type the type
     */
    public PDTypedDictionaryWrapper(String type)
    {
        super();
        this.getCOSDictionary().setName(COSName.TYPE, type);
    }

    /**
     *
     * @param dictionary the dictionary
     */
    public PDTypedDictionaryWrapper(COSDictionary dictionary)
    {
        super(dictionary);
    }


    /**
     * Returns the type.
     *
     * @return the type
     */
    public String getType()
    {
        return this.getCOSDictionary().getNameAsString(COSName.TYPE);
    }

}

--
Johannes Koch
Fraunhofer Institute for Applied Information Technology FIT
Web Compliance Center
Schloss Birlinghoven, D-53757 Sankt Augustin, Germany
Phone: +49-2241-142628    Fax: +49-2241-142065

Reply via email to