FxBinary.java :  » J2EE » fleXive » com » flexive » shared » value » Java Open Source

Java Open Source » J2EE » fleXive 
fleXive » com » flexive » shared » value » FxBinary.java
/***************************************************************
 *  This file is part of the [fleXive](R) project.
 *
 *  Copyright (c) 1999-2008
 *  UCS - unique computing solutions gmbh (http://www.ucs.at)
 *  All rights reserved
 *
 *  The [fleXive](R) project is free software; you can redistribute
 *  it and/or modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation;
 *  either version 2 of the License, or (at your option) any
 *  later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *  A copy is found in the textfile GPL.txt and important notices to the
 *  license from the author are found in LICENSE.txt distributed with
 *  these libraries.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  For further information about UCS - unique computing solutions gmbh,
 *  please see the company website: http://www.ucs.at
 *
 *  For further information about [fleXive](R), please see the
 *  project website: http://www.flexive.org
 *
 *
 *  This copyright notice MUST APPEAR in all copies of the file!
 ***************************************************************/
package com.flexive.shared.value;

import java.io.Serializable;
import java.util.Map;

/**
 * A multilingual Binary
 *
 * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
 */
public class FxBinary extends FxValue<BinaryDescriptor, FxBinary> implements Serializable {
    private static final long serialVersionUID = -4166874760670402680L;

    public final static BinaryDescriptor EMPTY = new BinaryDescriptor();

    /**
     * Constructor
     *
     * @param multiLanguage   multilanguage value?
     * @param defaultLanguage the default language
     * @param translations    HashMap containing language->translation mapping
     */
    public FxBinary(boolean multiLanguage, long defaultLanguage, Map<Long, BinaryDescriptor> translations) {
        super(multiLanguage, defaultLanguage, translations);
    }

    /**
     * Constructor
     *
     * @param defaultLanguage the default language
     * @param translations    HashMap containing language->translation mapping
     */
    public FxBinary(long defaultLanguage, Map<Long, BinaryDescriptor> translations) {
        super(defaultLanguage, translations);
    }

    /**
     * Constructor
     *
     * @param multiLanguage multilanguage value?
     * @param translations  HashMap containing language->translation mapping
     */
    public FxBinary(boolean multiLanguage, Map<Long, BinaryDescriptor> translations) {
        super(multiLanguage, translations);
    }

    /**
     * Constructor
     *
     * @param translations HashMap containing language->translation mapping
     */
    public FxBinary(Map<Long, BinaryDescriptor> translations) {
        super(translations);
    }

    /**
     * Constructor - create value from an array of translations
     *
     * @param translations HashMap containing language->translation mapping
     * @param pos          position (index) in the array to use
     */
    public FxBinary(Map<Long, BinaryDescriptor[]> translations, int pos) {
        super(translations, pos);
    }

    /**
     * Constructor
     *
     * @param multiLanguage   multilanguage value?
     * @param defaultLanguage the default language
     * @param value           single initializing value
     */
    public FxBinary(boolean multiLanguage, long defaultLanguage, BinaryDescriptor value) {
        super(multiLanguage, defaultLanguage, value);
    }

    /**
     * Constructor
     *
     * @param defaultLanguage the default language
     * @param value           single initializing value
     */
    public FxBinary(long defaultLanguage, BinaryDescriptor value) {
        super(defaultLanguage, value);
    }

    /**
     * Constructor
     *
     * @param multiLanguage multilanguage value?
     * @param value         single initializing value
     */
    public FxBinary(boolean multiLanguage, BinaryDescriptor value) {
        super(multiLanguage, value);
    }

    /**
     * Constructor
     *
     * @param value single initializing value
     */
    public FxBinary(BinaryDescriptor value) {
        super(value);
    }

    /**
     * Constructor
     *
     * @param clone original FxValue to be cloned
     */
    public FxBinary(FxValue<BinaryDescriptor, FxBinary> clone) {
        super(clone);
    }

    /**
     * Return true if T is immutable (e.g. java.lang.String). This prevents cloning
     * of the translations in copy constructors.
     *
     * @return true if T is immutable (e.g. java.lang.String)
     */
    @Override
    public boolean isImmutableValueType() {
        return true;
    }


    /**
     * Evaluates the given string value to an object of type T.
     *
     * @param value string value to be evaluated
     * @return the value interpreted as T
     */
    @Override
    public BinaryDescriptor fromString(String value) {
        return new BinaryDescriptor(value);
    }

    /** {@inheritDoc} */
    @Override
    public String getStringValue(BinaryDescriptor value) {
        return value.getHandle();
    }

    /**
     * Creates a copy of the given object (useful if the actual type is unknown).
     *
     * @return a copy of the given object (useful if the actual type is unknown).
     */
    @Override
    public FxBinary copy() {
        return new FxBinary(this);
    }

    /**
     * Replace all occurances of handle with the replacement BinaryDescriptor
     *
     * @param handle      the handle to replace
     * @param replacement the replacement
     */
    public void _replaceHandle(String handle, BinaryDescriptor replacement) {
        if (this.singleValue != null && this.singleValue.getHandle() != null &&
                this.singleValue.getHandle().equals(handle))
            this.singleValue = replacement;
        if (this.translations == null || this.translations.size() == 0)
            return;
        for (long bd_key : translations.keySet()) {
            if (translations.get(bd_key).getHandle() != null && translations.get(bd_key).getHandle().equals(handle))
                translations.put(bd_key, replacement);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Class<BinaryDescriptor> getValueClass() {
        return BinaryDescriptor.class;
    }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.