    001    // This file is part of the Attempto Java Packages.
    002    // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
    003    //
    004    // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the
    005    // terms of the GNU Lesser General Public License as published by the Free Software Foundation,
    006    // either version 3 of the License, or (at your option) any later version.
    007    //
    008    // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY
    009    // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    010    // PURPOSE. See the GNU Lesser General Public License for more details.
    011    //
    012    // You should have received a copy of the GNU Lesser General Public License along with the Attempto
    013    // Java Packages. If not, see http://www.gnu.org/licenses/.
    014
    015    package ch.uzh.ifi.attempto.chartparser;
    016
    017    /**
    018     * This class represents a string object that can unify with other string objects.
    019     *
    020     * @author Tobias Kuhn
    021     */
    022    public class StringRef {
    023
    024            private StringEntity stringEntity;
    025
    026            /**
    027             * Creates a new string object with null as value.
    028             */
    029            public StringRef() {
    030                    this((String) null);
    031            }
    032
    033            /**
    034             * Creates a new string object with the given value.
    035             *
    036             * @param string The value of the new string object.
    037             */
    038            public StringRef(String string) {
    039                    stringEntity = new StringEntity(string);
    040                    stringEntity.addReference(this);
    041            }
    042
    043            StringRef(StringEntity stringEntity) {
    044                    this.stringEntity = stringEntity;
    045                    stringEntity.addReference(this);
    046            }
    047
    048            void setStringEntity(StringEntity stringEntity) {
    049                    this.stringEntity = stringEntity;
    050            }
    051
    052            /**
    053             * Unifies this string object with another string object. If unification is not possible,
    054             * an exception is thrown.
    055             *
    056             * @param stringObj The string object to be unified with this string object.
    057             * @throws UnificationFailedException If unification fails.
    058             */
    059            public void unify(StringRef stringObj) throws UnificationFailedException {
    060                    stringEntity.unify(stringObj.stringEntity);
    061            }
    062
    063            /**
    064             * Returns the value of this string object.
    065             *
    066             * @return The value of this string object.
    067             */
    068            public String getString() {
    069                    return stringEntity.getString();
    070            }
    071
    072            int getID() {
    073                    return stringEntity.getID();
    074            }
    075
    076            StringEntity getStringEntity() {
    077                    return stringEntity;
    078            }
    079
    080    }