View Javadoc

1   /****************************************************************************
2    * Copyright (c) 2005, 2006, 2007, 2008, 2009 Imola Informatica.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the LGPL License v2.1
5    * which accompanies this distribution, and is available at
6    * http://www.gnu.org/licenses/lgpl.html
7    ****************************************************************************/
8   package it.imolinfo.jbi4corba.jbi.component;
9   
10  import it.imolinfo.jbi4corba.Logger;
11  import it.imolinfo.jbi4corba.LoggerFactory;
12  import it.imolinfo.jbi4corba.exception.ClassGenerationException;
13  import it.imolinfo.jbi4corba.exception.Jbi4CorbaDeployException;
14  import it.imolinfo.jbi4corba.exception.Jbi4CorbaException;
15  import it.imolinfo.jbi4corba.exception.Jbi4CorbaRuntimeException;
16  import it.imolinfo.jbi4corba.jbi.JbiServiceDescriptor;
17  import it.imolinfo.jbi4corba.jbi.Messages;
18  import it.imolinfo.jbi4corba.jbi.component.runtime.ComponentRuntime;
19  import it.imolinfo.jbi4corba.jbi.component.runtime.DefaultServiceUnitManager;
20  import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeConfiguration;
21  import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeContext;
22  import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeHelper;
23  import it.imolinfo.jbi4corba.jbi.endpoint.ConsumerEndpoint;
24  import it.imolinfo.jbi4corba.jbi.endpoint.Jbi4CorbaEndpoint;
25  import it.imolinfo.jbi4corba.jbi.endpoint.ProviderEndpoint;
26  import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaAddress;
27  import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaBinding;
28  import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtPreprocessDeserializer;
29  import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtension;
30  import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtensionRegistry;
31  import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtensionUtils;
32  import it.imolinfo.jbi4corba.utils.HelperFileUtil;
33  import it.imolinfo.jbi4corba.webservice.descriptor.ConsumerServiceDescriptor;
34  import it.imolinfo.jbi4corba.webservice.descriptor.ProviderServiceDescriptor;
35  import it.imolinfo.jbi4corba.webservice.generator.ChildFirstClassLoader;
36  import it.imolinfo.jbi4corba.webservice.generator.ClientCorbaClassesHolder;
37  import it.imolinfo.jbi4corba.webservice.generator.ProviderServiceClassesGenerator;
38  
39  import java.io.File;
40  import java.io.FileWriter;
41  import java.io.IOException;
42  import java.io.StringWriter;
43  import java.net.URLClassLoader;
44  import java.util.ArrayList;
45  import java.util.HashMap;
46  import java.util.Hashtable;
47  import java.util.List;
48  import java.util.Map;
49  import java.util.Properties;
50  import java.util.logging.Level;
51  
52  import javax.jbi.JBIException;
53  import javax.jbi.management.DeploymentException;
54  import javax.jbi.servicedesc.ServiceEndpoint;
55  import javax.management.MBeanException;
56  import javax.wsdl.Binding;
57  import javax.wsdl.Definition;
58  import javax.wsdl.PortType;
59  import javax.wsdl.Service;
60  import javax.wsdl.WSDLException;
61  import javax.wsdl.extensions.ExtensionRegistry;
62  import javax.wsdl.factory.WSDLFactory;
63  import javax.wsdl.xml.WSDLReader;
64  import javax.wsdl.xml.WSDLWriter;
65  import javax.xml.namespace.QName;
66  import javax.xml.parsers.DocumentBuilder;
67  import javax.xml.parsers.DocumentBuilderFactory;
68  import javax.xml.parsers.ParserConfigurationException;
69  import javax.xml.transform.OutputKeys;
70  import javax.xml.transform.Transformer;
71  import javax.xml.transform.dom.DOMSource;
72  import javax.xml.transform.stream.StreamResult;
73  
74  import org.apache.xml.resolver.CatalogManager;
75  import org.apache.xml.resolver.tools.CatalogResolver;
76  import org.xml.sax.EntityResolver;
77  
78  import com.ibm.wsdl.Constants;
79  import com.sun.jbi.eManager.provider.EndpointStatus;
80  import com.sun.jbi.eManager.provider.StatusProviderHelper;
81  import com.sun.jbi.eManager.provider.StatusReporting;
82  import com.sun.jbi.management.descriptor.ConfigurationException;
83  import com.sun.jbi.management.descriptor.EndpointIdentifier;
84  import com.sun.jbi.management.descriptor.SUDescriptorSupport;
85  import com.sun.wsdl4j.ext.impl.WSDLFactoryEx;
86  import com.sun.wsdl4j.ext.impl.WSDLReaderEx;
87  import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaIDLEntry;
88  import java.util.Arrays;
89  import java.util.Map.Entry;
90  import java.util.Set;
91  import javax.wsdl.Port;
92  import javax.wsdl.extensions.ExtensibilityElement;
93  import org.apache.commons.io.FileUtils;
94  
95  /**
96   * Jbi4Corba Service Unit Manager.
97   * Redefines: deploy/implement (no init).
98   * @see Jbi4CorbaLifeCycle  for more details of the generated code.
99   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
100  */
101 public class Jbi4CorbaSUManager extends DefaultServiceUnitManager {
102 
103     /** The Logger. */
104     private static final Logger LOG = LoggerFactory.getLogger(Jbi4CorbaSUManager.class);
105     /**
106      * The responsible to translate localized messages.
107      */
108     private static final Messages MESSAGES = Messages.getMessages(Jbi4CorbaSUManager.class);
109     /** The deployed endpoints. */
110     private List<Jbi4CorbaEndpoint> deployedEndpoints = new ArrayList<Jbi4CorbaEndpoint>();
111     /** The activated endpoints. */
112     private List<Jbi4CorbaEndpoint> activatedEndpoints = new ArrayList<Jbi4CorbaEndpoint>();
113     /** The life cycle. */
114     private Jbi4CorbaLifeCycle lifeCycle = null;
115     private TransformerPool mTransformerPool;
116     private RuntimeConfiguration runtimeConfiguration;
117     /**This Hashtable contains the genrated classes **/
118     private Hashtable<String, List<ClientCorbaClassesHolder>> classesTable;
119     private URLClassLoader tmpURLclassLoader = null;
120     private ChildFirstClassLoader tmpOriginaclassLoader = null;
121 
122     /**
123      * Constructor that takes the ComponentRuntime parameter.
124      *
125      * @param ctx the component runtime context
126      */
127     public Jbi4CorbaSUManager(ComponentRuntime ctx) {
128         super(ctx);
129         this.lifeCycle = (Jbi4CorbaLifeCycle) ctx.getLifeCycle();
130         mTransformerPool = new TransformerPool();
131         classesTable = new Hashtable<String, List<ClientCorbaClassesHolder>>();
132     }
133 
134     /**
135      * Deploy a Service Unit to the component.
136      *
137      * @param suName the service unit name
138      * @param suZipPath the service unit unzip path
139      *
140      * @return the xml message string
141      *
142      * @throws DeploymentException if some deploy problem occurs
143      *
144      * @see javax.jbi.component.ServiceUnitManager#deploy(String, String);
145      */
146     public String deploy(String suName, String suZipPath) throws DeploymentException {
147 
148         final String taskName = "deploy";
149         boolean isSuccess = true;
150 
151         LOG.info("CRB000214_Deploying_the_su_in_SA",
152                 new java.lang.Object[]{suName, suZipPath});
153 
154         // DO nothing...
155 
156         String retMsg = createComponentTaskResultXML(taskName, isSuccess);
157 
158         return retMsg;
159     }
160 
161     /**
162      * Start the deployed service unit.
163      *
164      * @param serviceUnitName the service unit name
165      *
166      * @throws DeploymentException if some problem occurs
167      *
168      * @see javax.jbi.component.ServiceUnitManager#start(String);
169      */
170     public void start(String serviceUnitName) throws javax.jbi.management.DeploymentException {
171 
172         LOG.debug("Starting the serviceUnit: " + serviceUnitName);
173         LOG.debug("Deployed Endpoints number: " + deployedEndpoints.size());
174 
175         // activate the SU deploy
176         for (Jbi4CorbaEndpoint endpoint : deployedEndpoints) {
177 
178             LOG.debug("endpoint.getSuName():" + endpoint.getSuName());
179             if (endpoint.getSuName().equals(serviceUnitName)) {
180                 try {
181                     // Register the service
182                     LOG.debug("Registering the service: " + endpoint.getServiceName());
183                     endpoint.registerService();
184 
185                     // Activate the endpoint
186                     endpoint.activate();
187 
188                     // Activate the endpoint
189                     LOG.debug("Activating the service for the bus: " + endpoint.getServiceName());
190                     activateEndpoint(endpoint);
191                     // Add the endpoint to the activated list
192                     activatedEndpoints.add(endpoint);
193 
194                 } catch (Jbi4CorbaException e) {
195                     LOG.error(e.getMessage());
196                     throw new DeploymentException(e);
197 
198                 }
199             }
200         }
201 
202     }
203 
204     /**
205      * Undeploy a service unit from the component.
206      *
207      * @param suZipPath
208      *            the service unit unzip path
209      * @param serviceUnitName
210      *            the service unit name
211      * @return the xml result message
212      *
213      * @throws DeploymentException
214      *             if some problem occurs
215      *
216      * @see javax.jbi.component.ServiceUnitManager#undeploy(String, String);
217      */
218     public String undeploy(String serviceUnitName, String suZipPath)
219             throws DeploymentException {
220         final String taskName = "undeploy";
221 
222         // Removes all unused classes from hashtable
223         List<String> keys = new ArrayList<String>();
224         //Remove the generated classes
225         for (String key : classesTable.keySet()) {
226             if (key.startsWith(serviceUnitName)) {
227                 keys.add(key);
228             }
229         }
230         for (String key : keys) {
231             classesTable.remove(key);
232         }
233 
234         //classesTable.remove(LOG);
235         boolean isSuccess = true;
236         // Do nothing...
237         String retMsg = createComponentTaskResultXML(taskName, isSuccess);
238         return retMsg;
239     }
240 
241     /**
242      * Stop the service unit.
243      *
244      * @param serviceUnitName the service unit name
245      * @throws DeploymentException if some problem occurs
246      */
247     public void stop(String serviceUnitName)
248             throws javax.jbi.management.DeploymentException {
249 
250         List<Jbi4CorbaEndpoint> endpointsToRemove = new ArrayList<Jbi4CorbaEndpoint>();
251 
252         // deactivate the SU deploy
253         for (Jbi4CorbaEndpoint corbaEndpoint : activatedEndpoints) {
254             if (corbaEndpoint.getSuName().equals(serviceUnitName)) {
255                 try {
256 
257                     // Unregister the service
258                     corbaEndpoint.deactivate();
259                     // Deactivate the endpoint
260                     deactivateEndpoint(corbaEndpoint);
261                     // Removes the endpoint from the activated endpoint list
262                     endpointsToRemove.add(corbaEndpoint);
263 
264                 } catch (Jbi4CorbaException e) {
265                     LOG.error(e.getMessage());
266                     throw new DeploymentException(e);
267 
268                 }
269             }
270         }
271         activatedEndpoints.removeAll(endpointsToRemove);
272     }
273     ///////////////////////////////////////////////////////////////////////////
274     // Service Unit Lifecycle Management methods implementation
275     ///////////////////////////////////////////////////////////////////////////
276     /* (non-Javadoc)
277      * @see it.imolinfo.jbi4ejb.jbi.component.runtime.DefaultServiceUnitManager#init(java.lang.String, java.lang.String)
278      */
279 
280     /**
281      * Service unit init, process the Endpoint deploy.
282      * @param serviceUnitName the service unit name
283      * @param serviceUnitRootPath the service unit root path
284      * @throws DeploymentException if some problem occurs
285      */
286     public void init(String serviceUnitName, String serviceUnitRootPath)
287             throws javax.jbi.management.DeploymentException {
288 
289         final StatusProviderHelper statusProviderHelper = lifeCycle.getStatusProviderHelper();
290         try {
291             // Gets the deployed endpoints and adds to the deployed endpoint list
292 
293             deployedEndpoints.addAll(processDeploy(serviceUnitName, serviceUnitRootPath, statusProviderHelper));
294             LOG.debug("Init: do nothing");
295         } catch (Exception ex) {
296             // TODOi18n
297             LOG.error("Failed to Deploy Service Unit:" + serviceUnitName + "\n" + ex, ex);
298 
299             throw new DeploymentException(ex);
300         }
301 
302     }
303 
304     /**
305      * Service unit shutdown, removes the deployed endpoint.
306      * @param serviceUnitName the service unit name
307      * @see javax.jbi.component.ServiceUnitManager#shutdown(String);
308      * @throws DeploymentException if some problem occurs
309      */
310     public void shutDown(String serviceUnitName)
311             throws javax.jbi.management.DeploymentException {
312 
313         // Removes the deployed endpoint
314         List<Jbi4CorbaEndpoint> deployedEndpointsToRemove = new ArrayList<Jbi4CorbaEndpoint>();
315         // remove the SU deployed endpoints
316         for (Jbi4CorbaEndpoint corbaEndpoint : deployedEndpoints) {
317             if (corbaEndpoint.getSuName().equals(serviceUnitName)) {
318                 deployedEndpointsToRemove.add(corbaEndpoint);
319             }
320         }
321         // Removes t he endpoints from the deployed endpoint list
322         deployedEndpoints.removeAll(deployedEndpointsToRemove);
323     }
324 
325     /**
326      * Returns the endpoint from using <code>ServiceEndpoint</code> from the started endpoint list.
327      * @param endpoint the ServiceEndpoint
328      * @return the <code>Jbi4CorbaEndpoint</code> if found, null otherwise
329      */
330     public Jbi4CorbaEndpoint getStartedEndpoint(ServiceEndpoint endpoint) {
331         LOG.debug("Activated endpoint size: " + activatedEndpoints.size());
332         return getEndpointFromList(endpoint, activatedEndpoints);
333     }
334 
335     /**
336      * Returns the endpoint from using <code>ServiceEndpoint</code> from the deployed endpoint list.
337      * @param endpoint the ServiceEndpoint
338      * @return the <code>Jbi4CorbaEndpoint</code> if found, null otherwise
339      */
340     public Jbi4CorbaEndpoint getDeployedEndpoint(ServiceEndpoint endpoint) {
341         LOG.debug("Deployed endpoint size: " + activatedEndpoints.size());
342         return getEndpointFromList(endpoint, deployedEndpoints);
343     }
344 
345     private boolean containsTrueCorbaWsdl(File file, EntityResolver resolver, Map envVariableMap) throws WSDLException {
346         final WSDLFactoryEx wsdlFactory = new WSDLFactoryEx();
347         final WSDLReaderEx reader = wsdlFactory.newWSDLReaderEx();
348         reader.setEntityResolver(resolver);
349         reader.setFeature(Constants.FEATURE_VERBOSE, true);
350         reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
351         reader.setExtensionRegistry(new Jbi4CorbaExtensionRegistry(envVariableMap));
352         //LOG.debug("Extension QName: " + Jbi4CorbaExtension.NS_URI_JBI4CORBA);
353         final Definition def = reader.readWSDL(file.getAbsolutePath());
354         Map serviceMap = def.getServices();
355         LOG.debug("servizi: " + Arrays.toString(serviceMap.keySet().toArray()));
356         for (Entry entry : (Set<Entry>) serviceMap.entrySet()) {
357             Service service = (Service) entry.getValue();
358             for (Entry portEntry : (Set<Entry>) service.getPorts().entrySet()) {
359                 Port port=(Port)portEntry.getValue();
360                 List extElems = port.getExtensibilityElements();
361                 LOG.debug("extensibility elements: " + Arrays.toString(extElems.toArray()));
362                 for (ExtensibilityElement extensibilityElement : (List<ExtensibilityElement>) extElems) {
363                     if (Jbi4CorbaAddress.class.isInstance(extensibilityElement)) {
364                         return true;
365                     }
366                 }
367             }
368         }
369         return false;
370     }
371 
372     /**
373      * Look for the endpoint in th endpoint list.
374      * @param endpoint the ServiceEndpoint
375      * @param endpointList the list to look for
376      * @return the <code>Jbi4CorbaEndpoint</code> if found, null otherwise
377      */
378     private Jbi4CorbaEndpoint getEndpointFromList(ServiceEndpoint endpoint, List<Jbi4CorbaEndpoint> endpointList) {
379 
380         for (Jbi4CorbaEndpoint corbaEndpoint : endpointList) {
381             LOG.debug("Looking for: " + endpoint.getServiceName() + "|" + endpoint.getEndpointName());
382 
383             // Two endpoits are the same if the Service and the Endpoint name is the same
384             if ((corbaEndpoint.getServiceName().equals(endpoint.getServiceName())) &&
385                     (corbaEndpoint.getEndpointName().equals(endpoint.getEndpointName()))) {
386                 LOG.debug("getEndpointFromList: Returning:" + corbaEndpoint);
387                 LOG.debug("getEndpointFromList: with service description:" + corbaEndpoint.getServiceDescription());
388                 return corbaEndpoint;
389             }
390 
391         }
392         LOG.debug("getEndpointFromList: Returning null");
393 
394         // endpoint not found
395         return null;
396     }
397 
398     private JbiServiceDescriptor getJbidesc(EndpointIdentifier epDesc, List<JbiServiceDescriptor> jbdescs) {
399         for (int i = 0; i < jbdescs.size(); i++) {
400             QName intname = new QName(jbdescs.get(i).getServiceNameSpace(), jbdescs.get(i).getServiceName());
401             if (epDesc.getInterfaceName().equals(intname)) {
402                 return jbdescs.get(i);
403             }
404         }
405         return jbdescs.get(0);
406     }
407 
408     private ProviderServiceDescriptor getProviderdesc(List<ProviderServiceDescriptor> psdesc, String serviceName) {
409         for (int i = 0; i < psdesc.size(); i++) {
410 
411             if (psdesc.get(i).getServiceName().equals(serviceName)) {
412                 return psdesc.get(i);
413             }
414         }
415         LOG.debug("getProviderdesc: Returning null");
416         return null;
417     }
418 
419     /**
420      * @throws ClassGenerationException
421      * Refactory
422      * Process deploy.
423      *
424      * @param suName the service unit name
425      * @param suZipPath the unzip path
426      *
427      * @return the list< jbi4 corba endpoint>
428      *
429      * @throws DeploymentException if some problem occurs
430      * @throws
431      */
432     private List<Jbi4CorbaEndpoint> processDeploy(String suName, String suZipPath, final StatusProviderHelper statusProviderHelper)
433             throws DeploymentException, IOException, Jbi4CorbaRuntimeException, ClassGenerationException {
434 
435         final File suDir = new File(suZipPath);
436 
437         //Generate the JbiServiceDescriptor and Populate the configuration Map
438         List<Jbi4CorbaSUInfo> jbisuInfo = new ArrayList<Jbi4CorbaSUInfo>();
439         List<JbiServiceDescriptor> jbdescs = getJbiDescriptors(suName, suZipPath, jbisuInfo);
440                
441         List<Jbi4CorbaEndpoint> endpoints = new ArrayList<Jbi4CorbaEndpoint>();
442 
443         ProviderServiceClassesGenerator serviceClassesGenerator = new ProviderServiceClassesGenerator();
444 
445         File rootDir = null;
446         if (jbdescs.size() > 0) {
447             rootDir = new File(
448                     suZipPath + File.separator + jbdescs.get(0).hashCode());
449 
450 
451             boolean resultMk = rootDir.mkdir();
452             if (!resultMk) {
453                 throw new DeploymentException(MESSAGES.getString(
454                         "CRB000201_Unable_to_create_working_directory",
455                         rootDir.getAbsolutePath()));
456             } else {
457                 LOG.debug("created working directory:" + rootDir.getAbsolutePath());
458             }
459 
460         }
461 
462         List<ProviderServiceDescriptor> psdesc = null;
463 
464 
465         //Collect all Descriptors and generate the classes
466         if (rootDir != null) {
467             psdesc = getProviderServiceDescriptor(suName, jbdescs, suZipPath, serviceClassesGenerator, rootDir);
468         }
469 
470         Jbi4CorbaEndpoint corbaEndpoint = null;
471         LOG.debug("The SU dir path is: " + suDir.getAbsolutePath());
472 
473         final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
474 
475         docBuilderFactory.setNamespaceAware(true);
476 
477         DocumentBuilder documentBuilder = null;
478 
479         try {
480             documentBuilder = docBuilderFactory.newDocumentBuilder();
481         } catch (ParserConfigurationException ex) {
482             String msg = MESSAGES.getString("CRB000216_Failure_in_creating_document_builder",
483                     new Object[]{ex.getMessage()});
484             LOG.error(msg, ex);
485             throw new DeploymentException(msg, ex);
486         }
487 
488         //if(SUDescriptorSupport.TEMP_SWITCH_ENABLE_JBI_ROUTING){
489         EndpointIdentifier epDesc;
490         File matchedWSDL;
491         Definition matchedDef;
492 
493         for (int i = 0; i < jbdescs.size(); i++) {
494 
495             epDesc = jbisuInfo.get(i).getEpIdentifier();
496             matchedWSDL = jbisuInfo.get(i).getMatchedWSDL();
497             matchedDef = jbisuInfo.get(i).getMatchedDef();
498 
499 
500             rootDir = new File(
501                     suZipPath + File.separator + jbdescs.get(i).hashCode());
502 
503 
504             if (epDesc.isProvider()) {
505 
506                 //PROVIDER
507                 corbaEndpoint = generateProvider(suZipPath,
508                         epDesc,
509                         getJbidesc(epDesc, jbdescs),
510                         getProviderdesc(psdesc, jbdescs.get(i).getServiceName()),
511                         rootDir);
512 
513             } else {
514 
515                 // CONSUMER
516                 // Gets the consumer service descriptor
517                 ConsumerServiceDescriptor consumerServiceDescriptor = getConsumerServiceDescriptor(epDesc, jbdescs.get(i), rootDir);                        //
518                 consumerServiceDescriptor.setServiceWSDLDefinition(matchedDef);
519                 String endpointNameLocalPart = QName.valueOf(epDesc.getEndpointName()).getLocalPart();
520                 corbaEndpoint = new ConsumerEndpoint(epDesc.getServiceName(), endpointNameLocalPart, consumerServiceDescriptor);
521             }
522 
523             // Reporting Stuff for monitoring Endpoint status
524             if (statusProviderHelper != null) {
525                 StatusReporting reporting = statusProviderHelper.getStatusReporter();
526                 String uniqueName = null;
527                 //if(reporting!=null){
528                 uniqueName = corbaEndpoint.getUniqueName();
529                 if (epDesc.isProvider()) {
530                     reporting.addProvisioningEndpoint(uniqueName);
531                 } else {
532                     reporting.addConsumingEndpoint(uniqueName);
533                 }
534                 EndpointStatus stat = reporting.getEndpointStatus(uniqueName);
535                 corbaEndpoint.setEndpointStatus(stat);
536             } else {
537                 LOG.warn("StatusProviderHelper is null.StatusReporting not created.");
538             }
539 
540             // Gets the endpoint data
541             corbaEndpoint.setDefinition(matchedDef);
542             corbaEndpoint.setState(Jbi4CorbaEndpoint.SHUTDOWN);
543             corbaEndpoint.setSuName(suName);
544             corbaEndpoint.setSuManager(this);
545             corbaEndpoint.setEndpointWSDL(matchedWSDL);
546 
547             if (corbaEndpoint != null) {
548                 try {
549                     //The Operation setServiceDescription(result); was moved on class ProviderEndpoint and ConsumerEndpoint
550                     //To fix error with wsdl that import schema.
551                     //corbaEndpoint.setServiceDescription(result);
552                     endpoints.add(corbaEndpoint);
553 
554                     populateEndpointWSDLInfo(corbaEndpoint.getEndpointStatus(), corbaEndpoint);
555                 } catch (Exception ex) {
556                     java.util.logging.Logger.getLogger(Jbi4CorbaSUManager.class.getName()).log(Level.SEVERE, null, ex);
557                 }
558             } else {
559                 LOG.debug("CorbaEndpoint is Null");
560             }
561         }
562         
563         return endpoints;
564     }
565 
566     @SuppressWarnings("unchecked")
567     public Map<String, String[]> parseForEnvironmentVariables(String suPath, Map<String, String[]> envVariableMap)
568             throws Jbi4CorbaRuntimeException {
569 
570         Map<String, String[]> envVariables =
571                 new HashMap<String, String[]>(envVariableMap);
572 
573         File catalog = new File(suPath +
574                 File.separator + "meta-inf" + File.separator +
575                 "catalog.xml");
576 
577         EntityResolver resolver = null;
578 
579         if (catalog.exists()) {
580             CatalogManager catalogManager = new CatalogManager();
581             catalogManager.setCatalogFiles(catalog.getAbsolutePath());
582             catalogManager.setRelativeCatalogs(true);
583             catalogManager.setUseStaticCatalog(false);
584             resolver = new CatalogResolver(catalogManager);
585         }
586 
587         for (File file : listWSDLFiles(new File(suPath))) {
588             try {
589                 envVariables.putAll(readWSDLForEnvVariables(file, resolver, envVariables));
590             } catch (WSDLException ex) {
591                 String msg = MESSAGES.getString("CRB000233_Error_in_parsing_environment_variables");
592                 LOG.error(msg, ex.getMessage());
593                 throw new Jbi4CorbaRuntimeException(ex);
594             }
595 
596         }
597 
598         return envVariables;
599     }
600 
601     @SuppressWarnings("unchecked")
602     private Map readWSDLForEnvVariables(File f, EntityResolver resolver, Map<String, String[]> envVariableMap)
603             throws WSDLException {
604 
605         WSDLFactoryEx wsdlFactory = new WSDLFactoryEx();
606         WSDLReaderEx reader = wsdlFactory.newWSDLReaderEx();
607         reader.setEntityResolver(resolver);
608         Jbi4CorbaExtPreprocessDeserializer preProcessDeserializer = new Jbi4CorbaExtPreprocessDeserializer(envVariableMap);
609         reader.setExtensionRegistry(new Jbi4CorbaExtensionRegistry(preProcessDeserializer));
610         reader.readWSDL(f.getAbsolutePath());
611         return preProcessDeserializer.getEnvVariableMap();
612     }
613 
614     @SuppressWarnings("unchecked")
615     private Definition readWSDL(File f, EntityResolver resolver, Map envVariableMap)
616             throws WSDLException {
617 
618         final WSDLFactoryEx wsdlFactory = new WSDLFactoryEx();
619         final WSDLReaderEx reader = wsdlFactory.newWSDLReaderEx();
620         reader.setEntityResolver(resolver);
621         reader.setFeature(Constants.FEATURE_VERBOSE, false);
622         reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
623         reader.setExtensionRegistry(new Jbi4CorbaExtensionRegistry(envVariableMap));
624         LOG.debug("Extension QName: " + Jbi4CorbaExtension.NS_URI_JBI4CORBA);
625         final Definition def = reader.readWSDL(f.getAbsolutePath());
626         return def;
627 
628     }
629 
630     /**
631      * Activate the endpoint.
632      * @param endpoint the ednpoint to activate
633      * @throws Jbi4CorbaDeployException if some deployment problem occurs
634      */
635     private void activateEndpoint(final Jbi4CorbaEndpoint endpoint) throws Jbi4CorbaDeployException {
636 
637         LOG.debug("Activating endpoint: " + endpoint.getUniqueName());
638 
639         if (activatedEndpoints.indexOf(endpoint) != -1) {
640             String msg = MESSAGES.getString("CRB000220_Failed_to_deploy_endpoint_because_already_registered",
641                     new Object[]{endpoint.getUniqueName()});
642             LOG.error(msg);
643             throw new Jbi4CorbaDeployException(msg);
644         }
645         try {
646             QName serviceName = (QName) endpoint.getServiceName();
647             ServiceEndpoint serviceEndpoint = RuntimeHelper.getComponentContext().activateEndpoint(endpoint.getServiceName(), endpoint.getEndpointName());
648 
649             endpoint.setServiceEndpoint(serviceEndpoint);
650             LOG.info("CRB000221_Endpoint_activated",
651                     new Object[]{serviceName});
652             endpoint.setState(Jbi4CorbaEndpoint.RUNNING);
653 
654         } catch (final JBIException me) {
655             String msg = MESSAGES.getString("CRB000222_Cannot_activate_endpoint",
656                     new Object[]{endpoint.getServiceName()}, new Object[]{me.getMessage()});
657             LOG.error(msg, me);
658             throw new Jbi4CorbaDeployException(msg, me);
659         }
660     }
661 
662     /**
663      * Activate the endpoint array.
664      * @param endpoint the endpoints to deactivate
665      * @throws Jbi4CorbaDeployException if some deployment problem occurs
666      */
667     public void deactivateEndpoint(final Jbi4CorbaEndpoint endpoint) throws Jbi4CorbaDeployException {
668         LOG.debug("Deactivating endpoint: " + endpoint.getUniqueName());
669 
670         if (!activatedEndpoints.contains(endpoint)) {
671             String msg = MESSAGES.getString("CRB000223_Endpoint_not_active",
672                     new Object[]{endpoint.getUniqueName()});
673             LOG.error(msg);
674             throw new Jbi4CorbaDeployException(msg);
675         } else {
676             try {
677                 RuntimeHelper.getComponentContext().deactivateEndpoint(endpoint.getServiceEndpoint());
678                 LOG.debug("Endpoint " + endpoint.getServiceEndpoint() + " deactivated");
679                 endpoint.setState(Jbi4CorbaEndpoint.STOPPED);
680             } catch (JBIException me) {
681                 String msg = MESSAGES.getString("CRB000224_Cannot_deactivate_endpoint",
682                         new Object[]{endpoint.getServiceName()}, new Object[]{me.getMessage()});
683                 LOG.error(msg, me);
684                 throw new Jbi4CorbaDeployException(msg, me);
685             }
686         }
687 
688     }
689 
690     /**
691      * Get all the WSDL file recursively in a directory.
692      * @param currentDir the directory where to search for the WSDLs
693      * @return the list of wsdl files
694      */
695     private List<File> listWSDLFiles(final File currentDir) {
696         final List<File> cumulativeResults = new ArrayList<File>();
697         final File[] filesInCurrentDir = currentDir.listFiles();
698 
699         for (File element : filesInCurrentDir) {
700 
701             if (element.isFile()) {
702 
703                 if (element.getName().toLowerCase().endsWith(".wsdl")) {
704                     cumulativeResults.add(element);
705                 }
706             } else if (element.isDirectory()) {
707                 final List<File> wsdlsInSubDirectories = listWSDLFiles(element);
708                 cumulativeResults.addAll(wsdlsInSubDirectories);
709             }
710         }
711         return cumulativeResults;
712     }
713 
714     /**
715      * Return all the files an definition in a <code>FileToDefinitionInfo</code>
716      * array.
717      *
718      * @param dir the directory where the WSDLs are
719      *
720      * @return the  <code>FileToDefinitionInfo</code> array
721      *
722      * @throws DeploymentException if some problem occurs
723      */
724     FileToDefinitionInfo[] readAllDefinitions(final File dir)
725             throws DeploymentException {
726 
727         final CatalogManager catalogManager = new CatalogManager();
728         catalogManager.setCatalogFiles(dir.getAbsolutePath() +
729                 File.separator + "xml-catalog.xml");
730         catalogManager.setRelativeCatalogs(true);
731 
732         final EntityResolver resolver = new CatalogResolver(catalogManager);
733 
734         final List<File> wsdls = listWSDLFiles(dir);
735         //final File[] wsdlFiles = (File[]) wsdls.toArray(new File[0]);
736 
737         // read all wsdl files to see if
738         //FileToDefinitionInfo[] fileToDefs = null;
739 
740         List<FileToDefinitionInfo> fileToDefsList = new ArrayList<FileToDefinitionInfo>();
741 
742         if (wsdls.size() > 0) {
743             //fileToDefs = new FileToDefinitionInfo[wsdlFiles.length];
744 
745             for (File file : wsdls) {
746                 Definition def = null;
747                 try {
748                     LOG.debug("esamino il file: " + file.getName() + " per vedere se è un vero wsdl corba ... ");
749                     boolean isTrueCorba = containsTrueCorbaWsdl(file, resolver, runtimeConfiguration.retrieveApplicationVariablesMap());
750                     LOG.debug("esaminato il file: " + file.getName() + " è un vero wsdl corba: " + isTrueCorba);
751                     if (isTrueCorba) {
752                         def = readWSDL(file, resolver, runtimeConfiguration.retrieveApplicationVariablesMap());
753                         fileToDefsList.add(new FileToDefinitionInfo(file, def));
754                     }
755                 } catch (WSDLException e) {
756                     String msg = MESSAGES.getString("CRB000225_Error_in_reading_wsdl_file",
757                             new Object[]{e.getMessage()});
758                     LOG.error(msg, e);
759                     throw new DeploymentException(msg, e);
760                 }
761 
762             }
763         }
764 
765         return fileToDefsList.toArray(new FileToDefinitionInfo[fileToDefsList.size()]);
766     }
767 
768     /**
769      * Reads a <code>Definition</code> from a <code>File</code>.
770      * @param f the file to read
771      * @return the WSDL definition
772      * @throws javax.wsdl.WSDLException if there are problem in reading the WSDL
773      */
774     public static Definition readWsdl(final File f) throws WSDLException {
775         final WSDLFactory wsdlFactory = WSDLFactory.newInstance();
776         ExtensionRegistry registry = wsdlFactory.newPopulatedExtensionRegistry();
777         final WSDLReader reader = wsdlFactory.newWSDLReader();
778         reader.setFeature(Constants.FEATURE_VERBOSE, false);
779         reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
780         Jbi4CorbaExtension.register(registry);
781         LOG.debug("Extension QName: " + Jbi4CorbaExtension.NS_URI_JBI4CORBA);
782         reader.setExtensionRegistry(registry);
783         final Definition def = reader.readWSDL(f.getAbsolutePath());
784         return def;
785     }
786 
787     /**
788      *  A value type for the file/definitions pairs.
789      */
790     static class FileToDefinitionInfo {
791 
792         /** The file. */
793         private File mFile;
794         /** The definition. */
795         private Definition mDefinition;
796 
797         /**
798          * Instantiates a new file to definition info.
799          *
800          * @param file the file
801          * @param definition the definition
802          */
803         FileToDefinitionInfo(final File file, final Definition definition) {
804             mFile = file;
805             mDefinition = definition;
806         }
807 
808         /**
809          * Gets the file.
810          *
811          * @return the file
812          */
813         public File getFile() {
814             return mFile;
815         }
816 
817         /**
818          * Gets the definition.
819          *
820          * @return the definition
821          */
822         public Definition getDefinition() {
823             return mDefinition;
824         }
825     }
826 
827     /**
828      * Gets the life cycle.
829      *
830      * @return the life cycle
831      */
832     public Jbi4CorbaLifeCycle getLifeCycle() {
833         return lifeCycle;
834     }
835 
836     /**
837      * Sets the life cycle.
838      *
839      * @param lifeCycle
840      *            the new life cycle
841      */
842     public void setLifeCycle(Jbi4CorbaLifeCycle lifeCycle) {
843         this.lifeCycle = lifeCycle;
844     }
845 
846     /**
847      * Gets the deployed endpoints.
848      *
849      * @return the deployed endpoints
850      */
851     public List<Jbi4CorbaEndpoint> getDeployedEndpoints() {
852         return deployedEndpoints;
853     }
854 
855     /**
856      * Creates the <code>JbiServiceDescriptor</code> from the extended
857      * WSDL-element. Creates also the idl file loaded from WSDL in the roortpath
858      * populating the JbiServiceDescriptor with the idlFileName and the
859      * idlFileNameDirectory.
860      *
861      * @param service               The service
862      * @param port                  The port
863      * @param binding               The binding
864      * @param addressExtension      The address extension
865      * @param bindingExtension      The binding extension
866      * @param rootPath              The root path
867      *
868      * @return                      The JbiServiceDescriptor created.
869      *
870      * @throws DeploymentException  The deployment exception
871      */
872     protected JbiServiceDescriptor createServiceDescriptor(
873             Service service,
874             Binding binding,
875             PortType portType,
876             Jbi4CorbaAddress addressExtension,
877             Jbi4CorbaBinding bindingExtension,
878             String role,
879             String rootPath) throws DeploymentException {
880 
881         JbiServiceDescriptor serviceDescriptor = new JbiServiceDescriptor();
882 
883         LOG.debug("Creating a JbiServiceDescriptor ... ");
884         // Raff: temp hack to make it compile
885 
886 
887         boolean idlFirstConsumer = (JbiServiceDescriptor.CONSUMER.equals(role) &&
888                 !bindingExtension.getJbi4CorbaDLEntryList().isEmpty());
889 
890         if (JbiServiceDescriptor.PROVIDER.equals(role) || idlFirstConsumer) {
891 
892             /*
893              * for every idl entry extract the idl and writes it into the root path
894              * if many wsdl are present in the su, all idl will be stored in the root path
895              * so the idlj an classes generation can run just once
896              */
897 
898             String idlFileName = null;
899 
900             for (Jbi4CorbaIDLEntry jbi4CorbaIDLEntry : bindingExtension.getJbi4CorbaDLEntryList()) {
901 
902                 // Calculate the IDL filename using the binding name (the local part)
903                 // and the rootPath. Replaces ":" (is a path separator) with "."
904                 String idl = jbi4CorbaIDLEntry.getIDL();
905                 String fileName = jbi4CorbaIDLEntry.getIdlFilename();
906                 String relativePath = jbi4CorbaIDLEntry.getRelativePath();
907                 boolean root = jbi4CorbaIDLEntry.isRoot();
908                 if (root) {
909                     idlFileName = fileName;
910                     relativePath = ".";
911                 }
912 
913                 LOG.debug("processing ideEntry: " + jbi4CorbaIDLEntry.getRelativePath() + File.separator + jbi4CorbaIDLEntry.getIdlFilename());
914 
915                 String idlAbsoluteFileName = rootPath + File.separator + relativePath + File.separator + fileName;
916 
917                 // Creates the IDL file in the SU directory
918                 LOG.debug("CRB000203_Producing_idl_file_to", new Object[]{idlAbsoluteFileName});
919                 FileWriter fr;
920                 try {
921                     File file = new File(idlAbsoluteFileName);
922                     File dir = new File(rootPath + File.separator + relativePath);
923                     //the file is created only the first time it appears
924                     if (!file.exists()) {
925                         if (!dir.exists()) {
926                             LOG.debug("creating directory: " + dir.getAbsolutePath());
927                             FileUtils.forceMkdir(dir);
928                         }
929                         file.createNewFile();
930                         fr = new FileWriter(file);
931                         fr.write(idl);
932                         fr.close();
933                     }
934                 } catch (IOException e) {
935                     String msg = MESSAGES.getString(
936                             "CRB000204_Unable_to_open_filename",
937                             idlAbsoluteFileName, e.getMessage());
938                     LOG.error(msg, e);
939                     throw new DeploymentException(msg, e);
940                 }
941 
942             }
943 
944             if (idlFileName == null) {
945                 String msg = MESSAGES.getString("CRB000236_No_Root_IDL_Entry_Defined");
946                 LOG.error(msg);
947                 throw new DeploymentException(msg);
948             }
949 
950 
951 
952             serviceDescriptor.setIdlFileName(idlFileName);
953             serviceDescriptor.setIdlFileNameDirectory(rootPath);
954 
955             serviceDescriptor.setPortTypeName(portType.getQName());
956 
957         } else if (JbiServiceDescriptor.CONSUMER.equals(role)) {
958             // Do nothing (all the configuration parameters has been depreceted...)
959         } else {
960             // Error: No recognized role
961             LOG.error("CRB000205_Invalid_role=", role);
962             throw new DeploymentException(
963                     MESSAGES.getString("CRB000205_Invalid_role=", role));
964         }
965 
966         // Commons configuration
967         serviceDescriptor.setRole(role);
968 
969         // Sets the namespace using the Service Namespace
970         serviceDescriptor.setServiceNameSpace(service.getQName().getNamespaceURI());
971         serviceDescriptor.setServiceName(service.getQName().getLocalPart());
972 
973         //This is for manage Endpoint that don't have ImolaCorba Address Extension
974         if (addressExtension != null) {
975             serviceDescriptor.setCorbaServiceName(addressExtension.getName());
976             serviceDescriptor.setLocalizationType(
977                     addressExtension.getLocalizationType());
978             serviceDescriptor.setOrbProperties(addressExtension.getOrbProperties());
979             serviceDescriptor.setPersistent(addressExtension.isPeristent());
980         }
981 
982 
983         LOG.debug("Created a JbiServiceDescriptor=" + serviceDescriptor);
984         return serviceDescriptor;
985     }
986 
987     /**
988      * This method gets an endpoint with a consumer role.
989      *
990      * @param   jbiServiceDescriptor  The jbi service descriptor
991      * @param   rootDir               The root Dir
992      */
993     private ConsumerServiceDescriptor getConsumerServiceDescriptor(
994             EndpointIdentifier epDesc,
995             JbiServiceDescriptor jbiServiceDescriptor,
996             File rootDir) {
997 
998         // here i must add endpoints for consumer role
999         ConsumerServiceDescriptor consumerServiceDescriptor = new ConsumerServiceDescriptor();
1000 
1001         consumerServiceDescriptor.setRootPath(
1002                 rootDir.getAbsolutePath());
1003         consumerServiceDescriptor.setServiceName(
1004                 jbiServiceDescriptor.getServiceName());
1005         consumerServiceDescriptor.setCorbaServiceName(
1006                 jbiServiceDescriptor.getCorbaServiceName());
1007 
1008         LOG.debug("Consumer CORBA name:" + consumerServiceDescriptor.getCorbaServiceName());
1009 
1010         consumerServiceDescriptor.setOrbProperties(
1011                 jbiServiceDescriptor.getOrbProperties());
1012         consumerServiceDescriptor.setLocalizationType(
1013                 jbiServiceDescriptor.getLocalizationType());
1014         consumerServiceDescriptor.setPersistent(jbiServiceDescriptor.isPersistent());
1015 
1016         // Sets the target endpoint (from the EndpointIdentifier)
1017         consumerServiceDescriptor.setTargetEndpoint(epDesc.getEndpointName());
1018         consumerServiceDescriptor.setTargetInterfaceName(epDesc.getInterfaceName());
1019         consumerServiceDescriptor.setTargetService(epDesc.getServiceName());
1020 
1021         consumerServiceDescriptor.setJbiServiceDescriptor(jbiServiceDescriptor);
1022 
1023         return consumerServiceDescriptor;
1024 
1025     }
1026 
1027     private void populateEndpointWSDLInfo(EndpointStatus endpointStatus, Jbi4CorbaEndpoint endpoint) throws Exception {
1028         //Set the resource info on the endpoint status if it is available
1029         Transformer transformer = mTransformerPool.retrieve();
1030         if (endpointStatus != null) {
1031             WSDLFactory wsdlFactory = (WSDLFactory) WSDLFactory.newInstance();
1032             @SuppressWarnings("unused")
1033             WSDLWriter writer = (WSDLWriter) wsdlFactory.newWSDLWriter();
1034 
1035             transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
1036             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
1037             StringWriter sw = new StringWriter();
1038             StreamResult result = new StreamResult(sw);
1039             DOMSource source = new DOMSource(endpoint.getServiceDescription());
1040             transformer.transform(source, result);
1041             endpointStatus.setWSDLDefinition(sw.toString());
1042 
1043             mTransformerPool.relinquish(transformer);
1044         }
1045 
1046     }
1047 
1048     /**
1049      * This method extract all jbiDescriptor from SU name and SU-zipPath
1050      * @param suName Service Unit name
1051      * @suZipPath
1052      * @infolist The holder of Jbi4CorbaSUInfo
1053      *
1054      * @throws  DeploymentException       The deployment exception
1055      **/
1056     @SuppressWarnings("unchecked")
1057     private List<JbiServiceDescriptor> getJbiDescriptors(String suName, String suZipPath, List<Jbi4CorbaSUInfo> infolist) throws DeploymentException {
1058 
1059 
1060         List<JbiServiceDescriptor> descList = new ArrayList<JbiServiceDescriptor>();
1061 
1062         final File suDir = new File(suZipPath);
1063         LOG.info("SERVICE UNIT DIRECTORY" + suDir.getAbsolutePath());
1064 
1065         // create application configuration object map from runtimeconfig
1066         if (runtimeConfiguration == null) {
1067             runtimeConfiguration = lifeCycle.getRuntimeConfiguration();
1068         }
1069 
1070         // Populate the Application Variables
1071 
1072         Map<String, String[]> envVariableMap =
1073                 parseForEnvironmentVariables(suZipPath, runtimeConfiguration.retrieveApplicationVariablesMap());
1074         if (envVariableMap.size() > runtimeConfiguration.countVariables()) {
1075             // number of environment variable tokens used in WSDLs
1076             // is greater than the ones defined
1077             try {
1078                 runtimeConfiguration.updateApplicationVariablesMap(envVariableMap);
1079             } catch (MBeanException e) {
1080                 String msg = MESSAGES.getString("CRB000234_Error_in_populating_the_application_variables");
1081                 LOG.error(msg, e.getMessage());
1082                 throw new Jbi4CorbaRuntimeException(e);
1083             }
1084         }
1085 
1086 
1087         // read all wsdl files.
1088 
1089         final FileToDefinitionInfo[] fileToDefs = readAllDefinitions(suDir);
1090 
1091 
1092 
1093         if (SUDescriptorSupport.TEMP_SWITCH_ENABLE_JBI_ROUTING) {
1094             LOG.debug("About to parse jbi.xml to resolve service end point in path:" + suDir.getAbsolutePath());
1095 
1096             EndpointIdentifier[] svcs = null;
1097 
1098             SUDescriptorSupport descSupport = null;
1099 
1100             try {
1101                 descSupport = new SUDescriptorSupport(
1102                         suDir.getAbsolutePath());
1103                 // Gets te service description from the jbi.xml
1104 
1105                 svcs = descSupport.getServices();
1106             } catch (ConfigurationException ex) {
1107                 String msg = MESSAGES.getString("CRB000217_Failure_in_getting_service_description",
1108                         new Object[]{ex.getMessage()});
1109                 LOG.error(msg, ex);
1110 
1111             }
1112 
1113             //Serrvice's number
1114             final int len = svcs.length;
1115 
1116             Map appConfigObjectMap = new HashMap();
1117             if (runtimeConfiguration != null) {
1118                 appConfigObjectMap = runtimeConfiguration.retrieveApplicationConfigurationsMap();
1119             }
1120 
1121             LOG.debug("Found " + svcs.length + " endpoint declared in the jbi.xml");
1122 
1123             //for each endpoint it create the jbidesc
1124             for (int i = 0; i < len; i++) {
1125                 Definition matchedDef = null;
1126                 File matchedWSDL = null;
1127 
1128                 Jbi4CorbaBinding corbaBinding = null;
1129                 Jbi4CorbaAddress corbaAddress = null;
1130 
1131                 // For each endpoint, analyzes the Definition.
1132                 EndpointIdentifier epDesc = svcs[i];
1133 
1134                 String configName = epDesc.getApplicationConfigurationName();
1135                 LOG.debug("Retrieved Application configuration Object name " + configName + " from Endpoint");
1136                 // this application configuration name is not yet defined in the config MBean,
1137                 // add it to the application configuration data structure
1138 
1139                 LOG.debug("Retrieved Application configuration Object name " + configName + " from Endpoint");
1140                 // this application configuration name is not yet defined in the config MBean,
1141                 // add it to the application configuration data structure
1142                 if (configName != null && !"".equals(configName) &&
1143                         !appConfigObjectMap.containsKey(configName)) {
1144                     appConfigObjectMap.put(configName, new String[3]);
1145                 }
1146                 String appconfigLocalizationType = null;
1147                 String appconfigaddressName = null;
1148                 String appconfigOrb = null;
1149                 if (configName != null && !"".equals(configName)) {
1150                     // there is a config object defined for the endpoint.
1151                     // use this instead of the values defined in the WSDL
1152 
1153                     String[] values = (String[]) appConfigObjectMap.get(configName);
1154                     if (values != null) {
1155                         //appconfigIdl = values[0] ;
1156                         appconfigLocalizationType = values[0];
1157                         appconfigaddressName = values[1];
1158                         appconfigOrb = values[2];
1159 
1160                         LOG.debug("The values of " + configName + " Application Configuration Object are " + appconfigLocalizationType + ", " + appconfigaddressName + ", " + appconfigOrb);
1161                     }
1162 
1163                 }
1164 
1165                 //For each wsdl link wsdl to endpoint
1166                 for (FileToDefinitionInfo element : fileToDefs) {
1167 
1168 
1169                     corbaBinding = Jbi4CorbaExtensionUtils.getCorbaBinding(element.getDefinition(), epDesc.getServiceName().toString(), epDesc.getEndpointName());
1170 
1171                     if (corbaBinding != null) {
1172                         matchedDef = element.getDefinition();
1173                         // this is the wsdl that contains the service
1174                         // endpoint, save it
1175                         matchedWSDL = element.getFile();
1176 
1177                         break;
1178                     }
1179 
1180                 }
1181 
1182                 corbaAddress = Jbi4CorbaExtensionUtils.getCorbaAddress(
1183                         matchedDef, epDesc.getServiceName().toString(),
1184                         epDesc.getEndpointName());
1185 
1186                 if (corbaAddress != null) {
1187 
1188                     if (appconfigLocalizationType != null && !appconfigLocalizationType.equals("")) {
1189                         LOG.debug("Replacing Localization Type " + corbaAddress.getLocalizationType() + " with " + appconfigLocalizationType);
1190                         corbaAddress.setLocalizationType(appconfigLocalizationType);
1191                     }
1192                     if (appconfigaddressName != null && !appconfigaddressName.equals("")) {
1193                         LOG.debug("Replacing Address Name " + corbaAddress.getName() + " with " + appconfigaddressName);
1194                         corbaAddress.setName(appconfigaddressName);
1195                     }
1196 
1197                     //Set the Orb properties
1198                     //************************
1199                     if (appconfigOrb != null && !appconfigOrb.equals("")) {
1200                         LOG.debug("Replacing ORB properties " + corbaAddress.getOrbProperties() + " with " + appconfigOrb);
1201                         Properties orbProp = corbaAddress.getOrbProperties();
1202                         // Process the name value pairs returned by the orb field
1203                         String[] nameValuePairs = appconfigOrb.split(",");
1204 
1205                         for (String nameValuePair : nameValuePairs) {
1206                             String[] nameAndValue = nameValuePair.split("=");
1207                             String key = nameAndValue[0];
1208                             String value = null;
1209                             if (nameAndValue.length > 1) {
1210                                 value = nameAndValue[1];
1211                             }
1212                             if (key != null && value != null && !key.equals("") && !value.equals("")) {
1213                                 String oldValue = (String) orbProp.put(key, value);
1214                                 LOG.debug("Set ORB property " + key + "=" + value + ".Previous value was" + oldValue);
1215 
1216                             }
1217                         }
1218 
1219                         corbaAddress.setOrbProperties(orbProp);
1220 
1221                     }
1222                 }
1223 
1224 
1225 
1226                 // Gets the endpoint data from the WSDL
1227                 Binding binding = Jbi4CorbaExtensionUtils.getBinding(matchedDef, epDesc.getServiceName().toString(), epDesc.getEndpointName());
1228                 Service service = Jbi4CorbaExtensionUtils.getService(matchedDef, epDesc.getServiceName().toString());
1229                 PortType portType = Jbi4CorbaExtensionUtils.getPortType(matchedDef, epDesc.getServiceName().toString(),
1230                         epDesc.getEndpointName());
1231                 String role = epDesc.isProvider() ? JbiServiceDescriptor.PROVIDER : JbiServiceDescriptor.CONSUMER;
1232 
1233                 // creates the service descriptor
1234 
1235                 JbiServiceDescriptor jbiServiceDescriptor = createServiceDescriptor(service,
1236                         binding,
1237                         portType,
1238                         corbaAddress,
1239                         corbaBinding,
1240                         role,
1241                         suZipPath);
1242 
1243                 Jbi4CorbaSUInfo info = new Jbi4CorbaSUInfo(epDesc, matchedDef, matchedWSDL, jbiServiceDescriptor);
1244                 infolist.add(info);
1245                 descList.add(jbiServiceDescriptor);
1246 
1247 
1248             }
1249         }
1250         LOG.info("JBI_DESC------> "+descList.toString());
1251         return descList;
1252 
1253     }
1254 
1255     /**
1256      * Generate The Provider Endpoint
1257      * @param suZipPath the unzip path
1258      * @param epDesc the endpoint Identifier
1259      * @param jbiServiceDescriptor
1260      * @param rootDir
1261      *
1262      * @return the provider jbi4CorbaEndpoint
1263      * @throws IOException, DeploymentException if some deployment problem occurs
1264      */
1265     private Jbi4CorbaEndpoint generateProvider(String suZipPath, EndpointIdentifier epDesc,
1266             JbiServiceDescriptor jbiServiceDescriptors, ProviderServiceDescriptor serviceDescriptor, File rootDir)
1267             throws IOException, DeploymentException {
1268 
1269 
1270 
1271         final String endpointNameLocalPart = QName.valueOf(epDesc.getEndpointName()).getLocalPart();
1272 
1273         Jbi4CorbaEndpoint corbaEndpoint = null;
1274 
1275         ProviderServiceDescriptor providerServiceDescriptor = null;
1276 
1277         providerServiceDescriptor = serviceDescriptor;
1278 
1279 
1280         try {
1281             corbaEndpoint = new ProviderEndpoint(epDesc.getServiceName(), endpointNameLocalPart, providerServiceDescriptor);
1282         } catch (Jbi4CorbaException e1) {
1283             String msg = MESSAGES.getString("CRB000235_Fail_to_generate_corba_endpoint");
1284             LOG.error(msg, e1.getMessage());
1285 
1286             throw new DeploymentException(e1);
1287         }
1288 
1289         return corbaEndpoint;
1290 
1291 
1292     }
1293 
1294     /**
1295      * Refactoring
1296      * This Class Return All the provider service descriptor from  multiple interface idl
1297      * Creates the provider service descriptor.
1298      *
1299      * @param   suName                    The service unit name
1300      * @param   jbiServiceDescriptor      The service unit root path
1301      * @param   serviceClassesGenerator   The service classes generator
1302      * @param   serviceUnitRootPath       The service unit root path
1303      * @param   rootDir                   The root Dir
1304      *
1305      * @throws  ClassGenerationException  The class generation exception
1306      * @throws  DeploymentException       The deployment exception
1307      *
1308      * @return the provider service descriptor
1309      */
1310     private List<ProviderServiceDescriptor> getProviderServiceDescriptor(String suName,
1311             List<JbiServiceDescriptor> jbiServiceDescriptor,
1312             String serviceUnitRootPath,
1313             ProviderServiceClassesGenerator serviceClassesGenerator,
1314             File rootDir) throws ClassGenerationException, IOException,
1315             DeploymentException {
1316 
1317         List<ProviderServiceDescriptor> providerServiceDescriptorList = new ArrayList<ProviderServiceDescriptor>();
1318         //*************************CLASS GENERATION**************************************************
1319         for (int i=0;i<jbiServiceDescriptor.size();i++){
1320         jbiServiceDescriptor.get(i).setIdlFileNameDirectory(serviceUnitRootPath);
1321         }
1322 
1323         //*************************Produce the classes only on the First Deploy********************
1324         //If the classes produced by an idl exists its take its from hashatable
1325 
1326         List<ClientCorbaClassesHolder> classes = null;
1327         List<JbiServiceDescriptor> tmpJbidescList = new ArrayList<JbiServiceDescriptor>(jbiServiceDescriptor);
1328         String idl = null;
1329         for (int i = 0; i < jbiServiceDescriptor.size(); i++) {
1330             if (jbiServiceDescriptor.get(i).getRole().equals(JbiServiceDescriptor.PROVIDER)) {
1331 
1332                 File idlFile = new File(jbiServiceDescriptor.get(i).getIdlFileNameDirectory() + File.separator +
1333                         jbiServiceDescriptor.get(i).getIdlFileName());
1334 
1335                 idl = HelperFileUtil.readFileAsString(idlFile).trim();
1336 
1337                 //if the classes is already generated takes it from hashtable
1338                 //The classKey is the union of the SUname and the hashcode of the idl
1339 
1340                 String classKey = suName + idl.hashCode();
1341                 tmpJbidescList.remove(jbiServiceDescriptor.get(i));
1342                 tmpJbidescList.add(0, jbiServiceDescriptor.get(i));
1343                 if (classesTable.get(classKey) != null) {
1344                     classes = classesTable.get(classKey);
1345 
1346                 } else {
1347 
1348                     classes = serviceClassesGenerator.generateProviderServiceClasses(
1349                             tmpJbidescList,
1350                             rootDir.getAbsolutePath(),
1351                             RuntimeContext.getInstance().getComponentContext().getInstallRoot(), null);
1352                     classesTable.put(classKey, classes);
1353                 }
1354 
1355 
1356         //*********************************************************************
1357         //List<ProviderServiceDescriptor> providerServiceDescriptorList = new ArrayList<ProviderServiceDescriptor>();
1358         //There is a CorbaClassesHolder for each idl interface
1359         //If the idl not has more than one interface  classes.size() = 1
1360 
1361 
1362 
1363 
1364         //For Each class return the correct providerServiceDescriptor
1365         //Bind class to relative providerServiceDescriptor
1366         if (classes != null) {
1367 
1368 
1369             for (ClientCorbaClassesHolder corbaClasses : classes) {
1370 
1371                         //Associate the correct jbidescriptor if there are more than 1
1372                         int start=corbaClasses.getOperationsClass().getName().lastIndexOf(".")+1;
1373                         int end=corbaClasses.getOperationsClass().getName().lastIndexOf("Operations");
1374                         String portypeName=corbaClasses.getOperationsClass().getName().substring(start, end);
1375                         String nameSpace="http://"+corbaClasses.getOperationsClass().getName().substring(0, end);
1376                         if (jbiServiceDescriptor.get(i).getPortTypeName().getLocalPart().equals(portypeName) &&
1377                                 jbiServiceDescriptor.get(i).getPortTypeName().getNamespaceURI().equals(nameSpace)
1378                                 || classes.size() == 1) {
1379                             LOG.debug("Provider -->"+jbiServiceDescriptor.get(i).getPortTypeName());
1380                             LOG.debug("ClientCorbaClassesHolder=" + corbaClasses);
1381 
1382                             ProviderServiceDescriptor providerServiceDescriptor = new ProviderServiceDescriptor();
1383 
1384 
1385                             providerServiceDescriptor.setValueTypeIdAndInstance(
1386                                     corbaClasses.getValueTypeIdAndInstance());
1387 
1388                             LOG.debug(corbaClasses.getValueTypeIdAndInstance().toString());
1389 
1390                             providerServiceDescriptor.setMethodSignatures(
1391                                     corbaClasses.getMethodSignatures());
1392 
1393                             providerServiceDescriptor.setAllUniontypes(
1394                                     corbaClasses.getAllUnionTypesMap());
1395 
1396                             providerServiceDescriptor.setSubstitutedUnionFields(
1397                                     corbaClasses.getSubstitutedUnionFields());
1398                             //Take Metadata Relative to Interface Type
1399                             providerServiceDescriptor.setAllInterfacetypes(
1400                                     corbaClasses.getAllInterafceTypesMap());
1401 
1402                             LOG.debug("********************************** InterfaceType *****======>" + corbaClasses.getAllInterafceTypesMap());
1403 
1404                             providerServiceDescriptor.setSubstitutedInterfaceFields(
1405                                     corbaClasses.getSubstitutedInterfaceFields());
1406 
1407                             providerServiceDescriptor.setAllIDLTypes(corbaClasses.getAllIDLTypes());
1408 
1409                             providerServiceDescriptor.setCorbaEnumMap(corbaClasses.getCorbaEnumMap());
1410 
1411                             providerServiceDescriptor.setIdToClassNameMap(corbaClasses.getIdToClassMap());
1412                             
1413                             providerServiceDescriptor.setTypeDefs(corbaClasses.getTypeDefs());
1414 
1415                             providerServiceDescriptor.setServiceNameSpace(
1416                                     jbiServiceDescriptor.get(i).getServiceNameSpace());
1417 
1418                             //Set the portTypeName of the descriptor with the name f the generated Class
1419                             providerServiceDescriptor.setPortTypeName(new QName(portypeName));
1420 
1421                             providerServiceDescriptor.setServiceInterface(
1422                                     corbaClasses.getOperationsClass());
1423                             providerServiceDescriptor.setCorbaHelperClass(
1424                                     corbaClasses.getHelperClass());
1425                             providerServiceDescriptor.setWsdlRootDirectory(serviceUnitRootPath);
1426                             //*****************************************************************************
1427                             if (serviceClassesGenerator.getUrlClassLoader() != null) {
1428                                 providerServiceDescriptor.setUrlClassLoader(
1429                                         serviceClassesGenerator.getUrlClassLoader());
1430                                 tmpURLclassLoader = serviceClassesGenerator.getUrlClassLoader();
1431                             } else {
1432                                 providerServiceDescriptor.setUrlClassLoader(tmpURLclassLoader);
1433                             }
1434 
1435                             LOG.debug("************ URL CLASS LOADER*******" + providerServiceDescriptor.getUrlClassLoader());
1436 
1437 
1438                             //*************Add the OriginalClassLoader For InvokeService********************
1439 
1440                             if (serviceClassesGenerator.getOriginalClassLoader() != null) {
1441                                 providerServiceDescriptor.setOriginalClassLoader(
1442                                         serviceClassesGenerator.getOriginalClassLoader());
1443                                 tmpOriginaclassLoader = serviceClassesGenerator.getOriginalClassLoader();
1444                             } else {
1445                                 providerServiceDescriptor.setOriginalClassLoader(tmpOriginaclassLoader);
1446                             }
1447 
1448                             LOG.debug("************ORIGINAL CLASS LOADER*******" + providerServiceDescriptor.getOriginalClassLoader());
1449 
1450                             //*********************************************************************************
1451                             String serviceName = jbiServiceDescriptor.get(i).getServiceName();
1452                             LOG.debug("ServiceName: " + serviceName);
1453                             if (serviceName == null) {
1454                                 LOG.error("CRB000206_No_ServiceName_found");
1455                                 throw new DeploymentException(MESSAGES.getString(
1456                                         "CRB000206_No_ServiceName_found"));
1457                             }
1458 
1459                             providerServiceDescriptor.setServiceName(serviceName);
1460                             providerServiceDescriptor.setCorbaServiceName(
1461                                     jbiServiceDescriptor.get(i).getCorbaServiceName());
1462 
1463                             LOG.debug("Provider CORBA name:" + providerServiceDescriptor.getCorbaServiceName());
1464 
1465                             providerServiceDescriptor.setOrbProperties(
1466                                     jbiServiceDescriptor.get(i).getOrbProperties());
1467                             providerServiceDescriptor.setLocalizationType(
1468                                     jbiServiceDescriptor.get(i).getLocalizationType());
1469 
1470                             providerServiceDescriptorList.add(providerServiceDescriptor);
1471 
1472                         }
1473                     }
1474 
1475             }
1476 
1477         }
1478         }
1479         //Remove the idl for regenerate the class
1480         return providerServiceDescriptorList;
1481 
1482     }
1483 }