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