KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > DeployedItemRefConfigFactory


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.enterprise.management.config;
24
25 import java.util.Set JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import java.io.Serializable JavaDoc;
30
31 import javax.management.ObjectName JavaDoc;
32 import javax.management.AttributeList JavaDoc;
33 import javax.management.RuntimeOperationsException JavaDoc;
34
35 import com.sun.appserv.management.base.Util;
36 import com.sun.appserv.management.base.XTypes;
37 import com.sun.appserv.management.util.jmx.JMXUtil;
38 import com.sun.appserv.management.util.misc.MapUtil;
39 import com.sun.appserv.management.util.misc.GSetUtil;
40 import com.sun.appserv.management.util.misc.TypeCast;
41
42 import com.sun.enterprise.management.support.oldconfig.OldApplicationsConfigMBean;
43
44 import com.sun.appserv.management.deploy.DeploymentStatus;
45 import com.sun.appserv.management.deploy.DeploymentSupport;
46
47 import com.sun.appserv.management.config.DeployedItemRefConfigCR;
48
49 /**
50     Base impl class for <application-ref>
51 */

52 public class DeployedItemRefConfigFactory extends ConfigFactory
53 {
54     private final OldApplicationsConfigMBean mOldApplicationsConfigMBean;
55     
56         public
57     DeployedItemRefConfigFactory(
58         final ConfigFactoryCallback callbacks)
59     {
60         super( callbacks );
61         
62         mOldApplicationsConfigMBean = getOldConfigProxies().getOldApplicationsConfigMBean();
63     }
64     
65     private final Set JavaDoc<String JavaDoc> LEGAL_OPTIONAL_KEYS =
66         GSetUtil.newUnmodifiableStringSet(
67         DeployedItemRefConfigCR.ENABLED_KEY,
68         DeployedItemRefConfigCR.VIRTUAL_SERVERS_KEY,
69         DeployedItemRefConfigCR.LB_ENABLED_KEY,
70         DeployedItemRefConfigCR.DISABLE_TIMEOUT_IN_MINUTES_KEY );
71     
72         protected Set JavaDoc<String JavaDoc>
73     getLegalOptionalCreateKeys()
74     {
75         return( LEGAL_OPTIONAL_KEYS );
76     }
77     
78         
79         protected Map JavaDoc<String JavaDoc,String JavaDoc>
80     getParamNameOverrides()
81     {
82         return( MapUtil.newMap( CONFIG_NAME_KEY, "ref" ) );
83     }
84                 
85     public ObjectName JavaDoc create(
86         final String JavaDoc referencedApplicationName,
87         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
88     {
89         trace( "DeployedItemRefConfigFactory.create: creating using: ");
90
91         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams( referencedApplicationName, null, optional );
92         
93         trace( "params as processed: " + stringify( params ) );
94
95         final ObjectName JavaDoc amxName = createNamedChild( referencedApplicationName, params );
96
97         return( amxName );
98     }
99           
100     public ObjectName JavaDoc create(
101         final String JavaDoc referencedApplicationName,
102         final boolean enabled,
103         final String JavaDoc virtualServers,
104         final boolean lbEnabled,
105         final int disableTimeoutInMinutes)
106     {
107         final Map JavaDoc<String JavaDoc,String JavaDoc> optionalParams = new java.util.HashMap JavaDoc<String JavaDoc,String JavaDoc>();
108         putNonNull( optionalParams, DeployedItemRefConfigCR.ENABLED_KEY,Boolean.toString(enabled));
109         putNonNull( optionalParams, DeployedItemRefConfigCR.VIRTUAL_SERVERS_KEY,virtualServers);
110         putNonNull( optionalParams, DeployedItemRefConfigCR.LB_ENABLED_KEY,Boolean.toString(lbEnabled));
111         putNonNull( optionalParams, DeployedItemRefConfigCR.DISABLE_TIMEOUT_IN_MINUTES_KEY,Integer.toString(disableTimeoutInMinutes));
112
113         final ObjectName JavaDoc amxName = create(referencedApplicationName, optionalParams);
114         return( amxName );
115     }
116
117         
118         public ObjectName JavaDoc
119     create(final String JavaDoc referencedApplicationName)
120     {
121         return create(referencedApplicationName, null);
122     }
123
124         
125         public void
126     internalRemove( final ObjectName JavaDoc objectName )
127     {
128         final String JavaDoc containerName = getFactoryContainer().getName();
129
130         mOldApplicationsConfigMBean.deleteApplicationReferenceAndReturnStatusAsMap(
131                 containerName, Util.getName( objectName ), null );
132     }
133
134         protected ObjectName JavaDoc
135     createOldChildConfig( final AttributeList JavaDoc translatedAttrs )
136     {
137         trace( "createOldChildConfig: attrs: " + stringify( translatedAttrs ) );
138
139         final String JavaDoc REF_KEY = "ref";
140
141         final Map JavaDoc<String JavaDoc,String JavaDoc> attributeMap = JMXUtil.attributeListToStringMap( translatedAttrs );
142
143         String JavaDoc appRef = null;
144         try
145         {
146             appRef = attributeMap.remove( REF_KEY );
147         }
148         catch ( UnsupportedOperationException JavaDoc uoe )
149         {
150             assert false;
151         }
152         assert appRef != null;
153
154         final String JavaDoc target = getFactoryContainer().getName();
155         assert target != null;
156
157         final ObjectName JavaDoc on = createApplicationRef( appRef, target, attributeMap );
158
159         return on;
160     }
161
162         private ObjectName JavaDoc
163     createApplicationRef( final String JavaDoc ref, final String JavaDoc target, final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
164     {
165         Map JavaDoc<String JavaDoc,Serializable JavaDoc> m = TypeCast.checkMap(
166             mOldApplicationsConfigMBean.
167                 createApplicationReferenceAndReturnStatusAsMap( target, ref, optional ),
168                 String JavaDoc.class,
169                 Serializable JavaDoc.class );
170         checkDeploymentStatusForExceptions( m );
171
172         final String JavaDoc targetJ2EEType = getFactoryContainer().getJ2EEType();
173
174         ObjectName JavaDoc on = null;
175         if ( XTypes.STANDALONE_SERVER_CONFIG.equals( targetJ2EEType ) )
176         {
177             on = getOldConfigProxies().getOldServerMBean( target ).
178                 getApplicationRefByRef( ref );
179         }
180         else if ( XTypes.CLUSTER_CONFIG.equals( targetJ2EEType ) )
181         {
182             on = getOldConfigProxies().getOldClusterMBean( target ).
183                 getApplicationRefByRef( ref );
184         }
185         else
186         {
187             throw new RuntimeException JavaDoc(
188             "Application refs can be created only on clusters and standalone servers" );
189         }
190
191         return on;
192     }
193
194         private void
195     checkDeploymentStatusForExceptions( Map JavaDoc<String JavaDoc,Serializable JavaDoc> m )
196     {
197         DeploymentStatus status = DeploymentSupport.mapToDeploymentStatus( m );
198         Throwable JavaDoc t = status.getStageThrowable();
199         final Iterator JavaDoc<DeploymentStatus> it = status.getSubStagesList().iterator();
200         while ( ( t == null ) && ( it.hasNext() ) )
201         {
202             status = it.next();
203             t = status.getThrowable();
204         }
205         if ( null != t )
206         {
207             throw new RuntimeException JavaDoc( status.getStageStatusMessage() );
208         }
209     }
210 }
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
Popular Tags