KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.io.File JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31 import javax.management.AttributeList JavaDoc;
32
33 import com.sun.appserv.management.config.TransformationRuleConfig;
34 import com.sun.appserv.management.config.TransformationRuleConfigKeys;
35 import com.sun.appserv.management.util.misc.GSetUtil;
36 import com.sun.appserv.management.base.Util;
37 import com.sun.enterprise.management.support.oldconfig.OldWebServiceEndpointConfigMBean;
38 import com.sun.enterprise.admin.wsmgmt.WebServiceMgrBackEnd;
39
40 import javax.xml.transform.stream.StreamSource JavaDoc;
41 import javax.xml.transform.TransformerFactory JavaDoc;
42 import javax.xml.transform.Transformer JavaDoc;
43
44 final class TransformationRuleConfigFactory extends ConfigFactory
45 {
46
47     private final OldWebServiceEndpointConfigMBean
48         mOldWebServiceEndpointConfigMBean;
49
50     private TransformerFactory JavaDoc _tFactory;
51     
52 public
53     TransformationRuleConfigFactory(
54         final ConfigFactoryCallback callbacks )
55     {
56         super( callbacks );
57
58          _tFactory = TransformerFactory.newInstance();
59
60         mOldWebServiceEndpointConfigMBean =
61         getOldWebServiceEndpointConfigMBean();
62     }
63
64     private final OldWebServiceEndpointConfigMBean
65     getOldWebServiceEndpointConfigMBean()
66     {
67         final String JavaDoc name = getFactoryContainer().getName();
68         return getOldConfigProxies().getOldWebServiceEndpointConfigMBean( name );
69
70     }
71                 
72   /**
73         The caller is responsible for dealing with any Properties.
74      */

75         protected ObjectName JavaDoc
76     createOldChildConfig(
77         final AttributeList JavaDoc translatedAttrs )
78     {
79             final ObjectName JavaDoc oldObjectName = (ObjectName JavaDoc)
80             getCallbacks().getDelegate().invoke(
81                 CREATE_TRANSFORMATION_RULE, new Object JavaDoc[] { translatedAttrs },
82                 CREATE_TRANSFORMATION_RULE_SIG );
83         
84         return oldObjectName;
85
86     }
87           
88         public ObjectName JavaDoc
89     create(
90         final String JavaDoc name,
91         final String JavaDoc ruleFileLocation,
92         final boolean enabled,
93         final String JavaDoc applyTo,
94         final Map JavaDoc<String JavaDoc,String JavaDoc> reserved )
95     {
96
97          String JavaDoc appId = getFactoryContainer().getContainer().getName();
98
99          String JavaDoc finalRuleFileLocation = null;
100          
101          try {
102              StreamSource JavaDoc stylesource =
103                    new StreamSource JavaDoc(new File JavaDoc(ruleFileLocation));
104             Transformer JavaDoc transformer = _tFactory.newTransformer(stylesource);
105
106              finalRuleFileLocation = WebServiceMgrBackEnd.getManager().
107                 moveFileToRepository(ruleFileLocation, appId);
108         } catch (Throwable JavaDoc t) {
109             throw new RuntimeException JavaDoc(t);
110         }
111          
112          Map JavaDoc<String JavaDoc,String JavaDoc> optional = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
113          optional.put(TransformationRuleConfigKeys.ENABLED_KEY,
114          Boolean.toString(enabled));
115          optional.put(TransformationRuleConfigKeys.APPLY_TO_KEY, applyTo);
116          final String JavaDoc[] requiredParams = new String JavaDoc[] {
117             TransformationRuleConfigKeys.RULE_FILE_LOCATION_KEY,
118             finalRuleFileLocation };
119
120         if (reserved != null) {
121             optional.putAll(reserved);
122         }
123
124         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams(name, requiredParams, optional);
125
126         trace( "params as processed: " + stringify( params ) );
127
128         final ObjectName JavaDoc amxName = createChild( params );
129         
130         return( amxName );
131     }
132
133         protected final void
134     removeByName(String JavaDoc name)
135     {
136         String JavaDoc appId = getFactoryContainer().getContainer().getName();
137         String JavaDoc epName = getFactoryContainer().getName();
138         WebServiceMgrBackEnd.getManager().
139                 removeFileFromRepository(appId,epName,name);
140         mOldWebServiceEndpointConfigMBean.removeTransformationRuleByName(name);
141     }
142
143
144     private final Set JavaDoc<String JavaDoc> LEGAL_OPTIONAL_KEYS =
145         GSetUtil.newUnmodifiableStringSet(
146         TransformationRuleConfigKeys.ENABLED_KEY,
147         TransformationRuleConfigKeys.APPLY_TO_KEY);
148     
149         protected Set JavaDoc<String JavaDoc>
150     getLegalOptionalCreateKeys()
151     {
152         return( LEGAL_OPTIONAL_KEYS );
153     }
154
155     private static final String JavaDoc CREATE_TRANSFORMATION_RULE =
156             "createTransformationRule";
157     private static final String JavaDoc[] CREATE_TRANSFORMATION_RULE_SIG =
158             new String JavaDoc[] { AttributeList JavaDoc.class.getName() };
159     private static final String JavaDoc REMOVE_TRANSFORMATION_RULE =
160             "removeTransformationRuleByName";
161     private static final String JavaDoc[] REMOVE_TRANSFORMATION_RULE_SIG =
162             new String JavaDoc[] { String JavaDoc.class.getName() };
163
164 }
165
166
167
168
169
170
Popular Tags