|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AppearanceDataBroker.java | 100% | 100% | 100% | 100% |
|
1 |
/*
|
|
2 |
|
|
3 |
VRMoo Common - Virtual Reality Object Oriented MUD Common Code
|
|
4 |
Copyright (C) 2003 VRMoo Development Team
|
|
5 |
|
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify
|
|
8 |
it under the terms of the GNU General Public License as published by
|
|
9 |
the Free Software Foundation; either version 2 of the License, or
|
|
10 |
(at your option) any later version.
|
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful,
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
GNU General Public License for more details.
|
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License
|
|
18 |
along with this program; if not, write to the Free Software
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
|
|
21 |
|
|
22 |
For information about VRMoo and its authors, please visit the website:
|
|
23 |
http://www.vrmoo.org/
|
|
24 |
|
|
25 |
*/
|
|
26 |
|
|
27 |
package org.vrmoo.common.objectbroker;
|
|
28 |
|
|
29 |
import org.vrmoo.common.data.AppearanceData;
|
|
30 |
import org.vrmoo.common.data.BrokerableObject;
|
|
31 |
import org.vrmoo.common.exception.VRMooException;
|
|
32 |
import org.vrmoo.common.exception.VRMooParseException;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* This class is a singleton responsible for handling the complex tasks of
|
|
36 |
* managing <code>ApperanceData</code> instances that are distributed between
|
|
37 |
* a world on the VRMoo Server and several VRMoo Clients.
|
|
38 |
*
|
|
39 |
* @author Jeff Weston
|
|
40 |
*/
|
|
41 |
public class AppearanceDataBroker extends AbstractObjectBroker |
|
42 |
{ |
|
43 |
/**
|
|
44 |
* The client instance of this class.
|
|
45 |
*/
|
|
46 |
private static AppearanceDataBroker clientInstance = null; |
|
47 |
|
|
48 |
/**
|
|
49 |
* Construct a server instance of this class.
|
|
50 |
*/
|
|
51 | 11 |
public AppearanceDataBroker( )
|
52 |
{ |
|
53 | 11 |
this( true ); |
54 |
} |
|
55 |
|
|
56 |
/**
|
|
57 |
* The client instance of this class is a singleton, so make the constructor
|
|
58 |
* that can create the client instance private. The client instance of this
|
|
59 |
* class can only be instantiated by the <code>getClientInstance()</code>
|
|
60 |
* method.
|
|
61 |
*
|
|
62 |
* @param isServerInstance tell this instance if it is a server instance
|
|
63 |
*/
|
|
64 | 12 |
private AppearanceDataBroker( boolean isServerInstance ) |
65 |
{ |
|
66 | 12 |
super( isServerInstance );
|
67 |
} |
|
68 |
|
|
69 |
/**
|
|
70 |
* Static method for getting the client instance of this class.
|
|
71 |
*
|
|
72 |
* @return the client instance of <code>ObjectDataBroker</code>
|
|
73 |
*/
|
|
74 | 11 |
public static synchronized AppearanceDataBroker getClientInstance( ) |
75 |
{ |
|
76 | 11 |
if ( clientInstance == null ) |
77 |
{ |
|
78 | 1 |
clientInstance = new AppearanceDataBroker( false ); |
79 |
} |
|
80 | 11 |
return clientInstance;
|
81 |
} |
|
82 |
|
|
83 |
/**
|
|
84 |
* Gets the <code>AppearanceData</code> with the specified name.
|
|
85 |
*
|
|
86 |
* @param name the name of the <code>AppearanceData</code> to retrieve
|
|
87 |
*
|
|
88 |
* @return the specified <code>AppearanceData</code>
|
|
89 |
*
|
|
90 |
* @throws VRMooException if the appearance name isn't found
|
|
91 |
*/
|
|
92 | 14 |
public AppearanceData getAppearanceData( String name )
|
93 |
throws VRMooException
|
|
94 |
{ |
|
95 | 14 |
return ( AppearanceData ) super.getBrokerableObject( name ); |
96 |
} |
|
97 |
|
|
98 |
/**
|
|
99 |
* Public interface for setting <code>AppearanceData</code> objects.
|
|
100 |
*
|
|
101 |
* @param appearanceData the <code>AppearanceData</code> to set
|
|
102 |
*/
|
|
103 | 13 |
public void setAppearanceData( AppearanceData appearanceData ) |
104 |
{ |
|
105 | 13 |
setBrokerableObject( appearanceData, null );
|
106 |
} |
|
107 |
|
|
108 |
/**
|
|
109 |
* Remove the <code>AppearanceData</code> with the specified name.
|
|
110 |
*
|
|
111 |
* @param name the name of the <code>ObjectData</code> to remove
|
|
112 |
*/
|
|
113 | 2 |
public synchronized void removeAppearanceData( String name ) |
114 |
{ |
|
115 | 2 |
removeBrokerableObject( name, null );
|
116 |
} |
|
117 |
|
|
118 |
/**
|
|
119 |
* Get the name of all of the <code>AppearanceData</code> objects available
|
|
120 |
* from this class.
|
|
121 |
*
|
|
122 |
* @return the array of <code>AppearanceData</code> names
|
|
123 |
*/
|
|
124 | 1 |
public synchronized String[ ] getAppearanceDataNames( ) |
125 |
{ |
|
126 | 1 |
return getBrokerableObjectNames( );
|
127 |
} |
|
128 |
|
|
129 |
/**
|
|
130 |
* Get the prefix used by this broker sub-class when sending or receiving
|
|
131 |
* commands.
|
|
132 |
*
|
|
133 |
* @return the prefix used for sending and receiving commands
|
|
134 |
*/
|
|
135 | 61 |
protected String getBrokerPrefix( )
|
136 |
{ |
|
137 | 61 |
return "appearanceDataBroker:"; |
138 |
} |
|
139 |
|
|
140 |
/**
|
|
141 |
* Get an instance of a brokerable object by parsing a string of encoded
|
|
142 |
* data representing the object.
|
|
143 |
*
|
|
144 |
* @param data the encoded data for the object
|
|
145 |
*
|
|
146 |
* @return the parsed <code>BrokerableObject</code>
|
|
147 |
*
|
|
148 |
* @throws VRMooParseException for any parsing errors that occur
|
|
149 |
*/
|
|
150 | 11 |
protected BrokerableObject parseBrokerableObject( String data )
|
151 |
throws VRMooParseException
|
|
152 |
{ |
|
153 | 11 |
return new AppearanceData( data ); |
154 |
} |
|
155 |
} |
|
156 |
|
|