| 1 | package desmoj.core.simulator; |
| 2 | |
| 3 | /** |
| 4 | * This superclass for every DESMOJ class provides the ability to carry a name |
| 5 | * for identification. Gives objects the ability to carry a name to be shown in |
| 6 | * reports. Each class in the desmoj-Framework is supposed to be able to carry a |
| 7 | * name for identification and offer methods to reset and tell its name. Since |
| 8 | * all other desmoj classes inherit from this class, it is ensured that any |
| 9 | * object, even the user's special objects, have a name to be used in a report. |
| 10 | * Offering no default constructor enforces users to give each new object in |
| 11 | * their models a name. The class is set abstract to prevent clients from |
| 12 | * accidentally creating otherwise functionless (but named) objects. |
| 13 | * |
| 14 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
| 15 | * @author Tim Lechler |
| 16 | * |
| 17 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 18 | * you may not use this file except in compliance with the License. You |
| 19 | * may obtain a copy of the License at |
| 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | * |
| 22 | * Unless required by applicable law or agreed to in writing, software |
| 23 | * distributed under the License is distributed on an "AS IS" |
| 24 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 25 | * or implied. See the License for the specific language governing |
| 26 | * permissions and limitations under the License. |
| 27 | * |
| 28 | */ |
| 29 | public abstract class NamedObject { |
| 30 | |
| 31 | /* |
| 32 | * The name of the namedObject as a String. |
| 33 | */ |
| 34 | private String _myName; |
| 35 | |
| 36 | /** |
| 37 | * Constructs a named object with the given initial name. Note, that this |
| 38 | * allows clients to produce more than one object with one name, thus being |
| 39 | * unable to distinguish those objects in reports! |
| 40 | * |
| 41 | * @param name |
| 42 | * java.lang.String : The given initial name for the named object |
| 43 | */ |
| 44 | public NamedObject(String name) { |
| 45 | |
| 46 | if (name == null) |
| 47 | _myName = "unnamed"; |
| 48 | else |
| 49 | _myName = name; |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns the name of the named object. This is the same name displayed in |
| 55 | * reports and trace files when this named object is shown in those reports |
| 56 | * or trace files. |
| 57 | * |
| 58 | * @return java.lang.String : The name of the named object |
| 59 | */ |
| 60 | public String getName() { |
| 61 | |
| 62 | return _myName; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the quoted name of the named object. This is the name displayed |
| 68 | * in reports and trace files when this named object is shown. |
| 69 | * |
| 70 | * @return java.lang.String : The quoted name of the named object |
| 71 | */ |
| 72 | public String getQuotedName() { |
| 73 | |
| 74 | return "'" + _myName + "'"; |
| 75 | |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Changes the name of the named object. This might be necessary for |
| 80 | * automatically created named object of a user defined model, but should |
| 81 | * not be used for elements of the framework or basic objects of the user |
| 82 | * model. Changing names of objects while runtime will confuse any trace |
| 83 | * output and generally make traces more difficult if not impossible to |
| 84 | * follow. |
| 85 | * |
| 86 | * @param newName |
| 87 | * java.lang.String : The new name for the named object |
| 88 | */ |
| 89 | protected void rename(String newName) { |
| 90 | |
| 91 | _myName = newName; |
| 92 | |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Overrides the java.lang.Object's toString method to return the named |
| 97 | * object's name when given as parameter to a method that expects a string |
| 98 | * to be passed. |
| 99 | * |
| 100 | * @return java.lang.String : The named object's name |
| 101 | */ |
| 102 | public String toString() { |
| 103 | |
| 104 | return _myName; |
| 105 | |
| 106 | } |
| 107 | } |