KickJava   Java API By Example, From Geeks To Geeks.

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


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  
24 /*
25  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/config/MailResourceConfigFactory.java,v 1.6 2006/03/17 03:34:15 llc Exp $
26  * $Revision: 1.6 $
27  * $Date: 2006/03/17 03:34:15 $
28  */

29
30
31 package com.sun.enterprise.management.config;
32
33 import java.util.Map JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.Collections JavaDoc;
36
37     
38 import javax.management.ObjectName JavaDoc;
39 import javax.management.AttributeList JavaDoc;
40
41 import com.sun.appserv.management.base.XTypes;
42 import com.sun.appserv.management.util.misc.MapUtil;
43 import com.sun.appserv.management.util.misc.GSetUtil;
44
45 import com.sun.appserv.management.config.MailResourceConfigKeys;
46 import com.sun.appserv.management.config.ResourceConfigKeys;
47 import com.sun.appserv.management.config.ResourceRefConfig;
48 import com.sun.appserv.management.config.Description;
49
50 public final class MailResourceConfigFactory extends ResourceFactoryImplBase
51 {
52         public
53     MailResourceConfigFactory(
54         final ConfigFactoryCallback callbacks )
55     {
56         super( callbacks );
57     }
58
59           
60     private final Set JavaDoc<String JavaDoc> LEGAL_OPTIONAL_KEYS =
61         GSetUtil.newUnmodifiableStringSet(
62         MailResourceConfigKeys.STORE_PROTOCOL_KEY,
63         MailResourceConfigKeys.STORE_PROTOCOL_CLASS_KEY,
64         MailResourceConfigKeys.TRANSPORT_PROTOCOL_KEY,
65         MailResourceConfigKeys.TRANSPORT_PROTOCOL_CLASS_KEY,
66         MailResourceConfigKeys.DEBUG_KEY,
67         Description.DESCRIPTION_KEY,
68         ResourceConfigKeys.ENABLED_KEY );
69     
70         protected Set JavaDoc<String JavaDoc>
71     getLegalOptionalCreateKeys()
72     {
73         return( LEGAL_OPTIONAL_KEYS );
74     }
75     
76     
77     public static final String JavaDoc HOST_KEY = "Host";
78     public static final String JavaDoc USER_KEY = "User";
79     public static final String JavaDoc FROM_KEY = "From";
80     
81           
82         protected Map JavaDoc<String JavaDoc,String JavaDoc>
83     getParamNameOverrides()
84     {
85         return( MapUtil.newMap( CONFIG_NAME_KEY, "jndi-name" ) );
86     }
87
88                 
89         /**
90         The caller is responsible for dealing with any Properties.
91      */

92         protected ObjectName JavaDoc
93     createOldChildConfig(
94         final AttributeList JavaDoc translatedAttrs )
95     {
96         trace( "MailResourceConfigFactory.createOldChildConfig: creating using: " +
97             stringify( translatedAttrs ) );
98             
99         final ObjectName JavaDoc objectName =
100                 getOldResourcesMBean().createMailResource( translatedAttrs );
101         
102         return( objectName );
103     }
104
105
106     /**
107         Create a new &lt;mail-resource>
108         
109         @param jndiName
110         @param host
111                 @param user
112                 @param from
113         @param optional
114      */

115         public ObjectName JavaDoc
116     create( String JavaDoc jndiName,
117         String JavaDoc host,
118         String JavaDoc user,
119         String JavaDoc from,
120         Map JavaDoc<String JavaDoc,String JavaDoc> optional)
121     {
122         final String JavaDoc[] requiredParams = new String JavaDoc[]
123         {
124         HOST_KEY, host,
125         USER_KEY, user,
126         FROM_KEY, from,
127         };
128             
129         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams( jndiName, requiredParams, optional );
130
131         final ObjectName JavaDoc amxName = createNamedChild( jndiName, params );
132
133         return( amxName );
134     }
135     
136         final protected void
137     removeByName( String JavaDoc name )
138     {
139         final Set JavaDoc<ResourceRefConfig> refs =
140             findAllRefConfigs( XTypes.MAIL_RESOURCE_CONFIG, name );
141         
142         if ( refs.size() == 0 )
143         {
144             getOldResourcesMBean().removeMailResourceByJndiName( name );
145         }
146         else
147         {
148             for( final ResourceRefConfig ref : refs )
149             {
150                 final String JavaDoc target = ref.getContainer().getName();
151                 getOldResourcesMBean().deleteMailResource( name, target );
152             }
153         }
154     }
155     
156     
157     
158 }
159
160
Popular Tags