KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > deploy > DeploymentStatusImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.appserv.management.deploy;
24
25 import java.util.Map JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collections JavaDoc;
30
31 import java.io.Serializable JavaDoc;
32
33 import com.sun.appserv.management.util.misc.TypeCast;
34 import com.sun.appserv.management.base.OperationStatusBase;
35
36
37 import com.sun.appserv.management.base.AMXDebug;
38
39 /**
40     <b>Not for public use.</b> Use {@link DeploymentSupport} to
41     create a DeploymentStatus from a Map.
42  */

43 public final class DeploymentStatusImpl
44     extends OperationStatusBase
45     implements DeploymentStatus
46 {
47     transient DeploymentStatus mParent;
48     
49         public
50     DeploymentStatusImpl( final DeploymentStatus src )
51     {
52         this( src.asMap(), true );
53     }
54     
55         private <T extends Serializable JavaDoc>
56     DeploymentStatusImpl(
57         final Map JavaDoc<String JavaDoc,T> m,
58         final boolean doValidate )
59     {
60         super( m, DEPLOYMENT_STATUS_CLASS_NAME );
61         
62         checkValidType( m, DEPLOYMENT_STATUS_CLASS_NAME );
63         mParent = null;
64         
65         convertSubStages();
66         if ( doValidate && ! validate() )
67         {
68             throw new IllegalArgumentException JavaDoc( toString() );
69         }
70     }
71     
72     /**
73         Create a new instance. The Map must contain the following
74         keyed values:
75         
76         <ul>
77         <li>{@link com.sun.appserv.management.base.MapCapable}.MAP_CAPABLE_TYPE_KEY with
78             value DEPLOYMENT_STATUS_CLASS_NAME</li>
79         <li>STAGE_STATUS_KEY</li>
80         <li>STAGE_STATUS_MESSAGE_KEY</li>
81         </ul>
82         
83         The map may contain values keyed by any of the
84         following:
85         <ul>
86         <li>SUB_STAGES_KEY</li>
87         <li>STAGE_THROWABLE_KEY</li>
88         <li>STAGE_DESCRIPTION_KEY</li>
89         </ul>
90         
91         @param m a Map representing a DeploymentStatus
92      */

93         public <T extends Serializable JavaDoc>
94     DeploymentStatusImpl( final Map JavaDoc<String JavaDoc,T> m )
95     {
96         this( m, true );
97         convertSubStages();
98     }
99     
100     /**
101         Create a new instance. The 'optional' Map may contain any of the value
102         keys as found in this( Map m ). Values supplied in the Map, if conflicting
103         with other parameters, are overwritten in the resulting new DeploymentStatusImpl.
104         
105         @param stageStatus
106         @param stageStatusMessage
107         @param stageDescription
108      */

109         public <T extends Serializable JavaDoc>
110     DeploymentStatusImpl(
111         final int stageStatus,
112         final String JavaDoc stageStatusMessage,
113         final String JavaDoc stageDescription,
114         final Map JavaDoc<String JavaDoc,T> optional )
115     {
116         super( null, DEPLOYMENT_STATUS_CLASS_NAME );
117
118         putAll( optional );
119         
120         setStageStatus( stageStatus );
121         setStageStatusMessage( stageStatusMessage == null ? "" : stageStatusMessage );
122         setStageDescription( stageDescription == null ? "" : stageDescription );
123         
124         convertSubStages();
125         if ( ! validate() )
126         {
127             throw new IllegalArgumentException JavaDoc( );
128         }
129     }
130     
131         private void
132     convertSubStages()
133     {
134         final List JavaDoc<?> value = List JavaDoc.class.cast( getField( SUB_STAGES_KEY ) );
135         if ( value != null && value.size() != 0 )
136         {
137             final List JavaDoc<DeploymentStatus> ssList = new ArrayList JavaDoc<DeploymentStatus>();
138             
139             for( final Object JavaDoc o : value )
140             {
141                 DeploymentStatus ds = null;
142                 if ( o instanceof Map JavaDoc )
143                 {
144                     final Map JavaDoc<String JavaDoc,Serializable JavaDoc> m = TypeCast.asMap(o);
145                     ds = new DeploymentStatusImpl(m,true);
146                 }
147                 else if ( o instanceof DeploymentStatus )
148                 {
149                      // not necessarily the same implementation + always make a copy
150
final DeploymentStatus in = (DeploymentStatus)o;
151                     ds = new DeploymentStatusImpl( in );
152                 }
153                 else
154                 {
155                     throw new IllegalArgumentException JavaDoc();
156                 }
157                 ds.setParent(this);
158                 ssList.add( ds );
159             }
160             putField( SUB_STAGES_KEY, (Serializable JavaDoc)ssList );
161         }
162     }
163     
164     /**
165      */

166      @Override JavaDoc
167         protected Serializable JavaDoc
168     asMapHook( final String JavaDoc key, final Serializable JavaDoc value )
169     {
170         Serializable JavaDoc result = value;
171         
172         if ( SUB_STAGES_KEY.equals( key ) )
173         {
174             // convert substages to Map as well
175
final List JavaDoc<?> l = List JavaDoc.class.cast( value );
176             if ( l != null && l.size() != 0 )
177             {
178                 final List JavaDoc<DeploymentStatus> lds =
179                     TypeCast.checkList( l, DeploymentStatus.class );
180             
181                 final ArrayList JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>> maps =
182                     new ArrayList JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>>();
183                 
184                 for( final DeploymentStatus ds : lds )
185                 {
186                     maps.add( ds.asMap() );
187                 }
188                 result = maps;
189             }
190         }
191         else
192         {
193             result = super.asMapHook(key, value );
194         }
195         
196         return result;
197     }
198     
199         protected boolean
200     validate()
201     {
202         boolean valid = getInteger( STAGE_STATUS_KEY ) != null;
203         assert( valid ) : "STAGE_STATUS_KEY missing";
204         if ( valid )
205         {
206             if ( getString( STAGE_STATUS_MESSAGE_KEY ) == null )
207             {
208                 putField( STAGE_STATUS_MESSAGE_KEY, "N/A" );
209             }
210         }
211         
212         if ( valid )
213         {
214             final List JavaDoc<?> value = List JavaDoc.class.cast( getField( SUB_STAGES_KEY ) );
215             final List JavaDoc<DeploymentStatus> subStages =
216                 TypeCast.checkList( value, DeploymentStatus.class );
217         }
218         
219         return( valid );
220     }
221     
222     
223         public String JavaDoc
224     getStageDescription()
225     {
226         return( getString( STAGE_DESCRIPTION_KEY ) );
227     }
228     
229         public void
230     setStageDescription( final String JavaDoc description )
231     {
232         putField( STAGE_DESCRIPTION_KEY, description );
233     }
234     
235     
236         public String JavaDoc
237     getStageStatusMessage()
238     {
239         return( getString( STAGE_STATUS_MESSAGE_KEY ) );
240     }
241     
242     
243         public void
244     setStageStatusMessage( final String JavaDoc message )
245     {
246         putField( STAGE_STATUS_MESSAGE_KEY, message );
247     }
248     
249     
250         public int
251     getStageStatus()
252     {
253         return( getStatusCode() );
254     }
255     
256         public void
257     setStageStatus( int status )
258     {
259         setStatusCode( status );
260     }
261     
262         private List JavaDoc<DeploymentStatus>
263     getDeploymentStatusField()
264     {
265         final List JavaDoc<?> value = List JavaDoc.class.cast( getField( SUB_STAGES_KEY ) );
266         final List JavaDoc<DeploymentStatus> subStages =
267             TypeCast.checkList( value, DeploymentStatus.class );
268         return subStages;
269     }
270     
271         public void
272     addSubStage( final DeploymentStatus status )
273     {
274         status.setParent( this );
275         
276         List JavaDoc<DeploymentStatus> subStages = getDeploymentStatusField();
277         if ( subStages == null )
278         {
279             subStages = new ArrayList JavaDoc<DeploymentStatus>();
280             
281             putField( SUB_STAGES_KEY, (Serializable JavaDoc)subStages );
282         }
283         
284         subStages.add( status );
285     }
286     
287         public Iterator JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>>
288     getSubStages()
289     {
290         List JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>> maps = null;
291         
292         final List JavaDoc<DeploymentStatus> subStages = getSubStagesList();
293         if ( subStages != null )
294         {
295             maps = new ArrayList JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>>();
296             for( final DeploymentStatus ds : subStages )
297             {
298                 maps.add( ds.asMap() );
299             }
300         }
301         else
302         {
303             maps = Collections.emptyList();
304         }
305         
306         return maps.iterator();
307     }
308     
309         public List JavaDoc<DeploymentStatus>
310     getSubStagesList()
311     {
312         List JavaDoc<DeploymentStatus> subStages = getDeploymentStatusField();
313         TypeCast.checkList( subStages, DeploymentStatus.class );
314         
315         if ( subStages == null )
316         {
317             subStages = Collections.emptyList();
318         }
319         else
320         {
321             subStages = Collections.unmodifiableList( subStages );
322         }
323         
324         return subStages;
325     }
326     
327         public DeploymentStatus
328     getParent()
329     {
330         return( mParent );
331     }
332     
333         public void
334     setParent( final DeploymentStatus parent )
335     {
336         mParent = parent;
337     }
338     
339         public Throwable JavaDoc
340     getStageThrowable()
341     {
342         return( getThrowable( ) );
343     }
344     
345         public void
346     setStageThrowable( Throwable JavaDoc t)
347     {
348         setThrowable( t );
349     }
350
351
352         public Map JavaDoc<String JavaDoc,Serializable JavaDoc>
353     getAdditionalStatus()
354     {
355         return( getMap( ADDITIONAL_STATUS_KEY ) );
356     }
357
358
359         public void
360     setAdditionalStatus( final Map JavaDoc<String JavaDoc,Serializable JavaDoc> additionalStatus )
361     {
362         if ( ! (additionalStatus instanceof Serializable JavaDoc) )
363         {
364             throw new IllegalArgumentException JavaDoc( "Class is not Serializable: " +
365                 additionalStatus.getClass().getName() );
366         }
367
368         putField( ADDITIONAL_STATUS_KEY, (Serializable JavaDoc)additionalStatus );
369     }
370     
371     
372         public boolean
373     equals( final Object JavaDoc rhs)
374     {
375         boolean equal = false;
376         
377         if ( rhs instanceof DeploymentStatus && ! (rhs instanceof DeploymentStatusImpl) )
378         {
379             equal = super.equals( new DeploymentStatusImpl( (DeploymentStatus)rhs ) );
380         }
381         else
382         {
383             equal = super.equals( rhs );
384         }
385         
386         return( equal );
387     }
388 }
389
390
391
392
393
394
395
396
397
Popular Tags