KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > converters > EndpointConverter


1 /*
2  * $Id: EndpointConverter.java 3831 2006-11-07 22:29:59Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.config.converters;
12
13 import org.apache.commons.beanutils.ConversionException;
14 import org.apache.commons.beanutils.Converter;
15 import org.mule.MuleManager;
16 import org.mule.impl.endpoint.MuleEndpoint;
17 import org.mule.impl.endpoint.MuleEndpointURI;
18 import org.mule.umo.endpoint.UMOEndpoint;
19 import org.mule.umo.endpoint.UMOEndpointURI;
20 import org.mule.umo.endpoint.UMOImmutableEndpoint;
21 import org.mule.umo.manager.UMOManager;
22
23 /**
24  * <code>EndpointConverter</code> TODO
25  */

26 public class EndpointConverter implements Converter
27 {
28
29     // --------------------------------------------------------- Public Methods
30

31     /**
32      * Convert the specified input object into an output object of the specified
33      * type.
34      *
35      * @param type Data type to which this value should be converted
36      * @param value The input value to be converted
37      * @throws ConversionException if conversion cannot be performed successfully
38      */

39     public Object JavaDoc convert(Class JavaDoc type, Object JavaDoc value)
40     {
41         UMOManager manager = MuleManager.getInstance();
42         if (value == null)
43         {
44             throw new ConversionException("No value specified");
45         }
46         if (value instanceof UMOEndpoint)
47         {
48             return (value);
49         }
50         try
51         {
52             String JavaDoc endpointString = manager.lookupEndpointIdentifier(value.toString(), value.toString());
53             UMOImmutableEndpoint globalEndpoint = (UMOImmutableEndpoint)manager.getEndpoints().get(
54                 endpointString);
55             if (globalEndpoint == null)
56             {
57                 UMOEndpointURI endpointUri = new MuleEndpointURI(endpointString);
58                 if (!endpointString.equals(value.toString()))
59                 {
60                     endpointUri.setEndpointName(value.toString());
61                 }
62                 UMOEndpoint endpoint = MuleEndpoint.createEndpointFromUri(endpointUri, null);
63                 // If the value was an endpoint identifier reference then set
64
// the
65
// reference as the name of the endpoint
66
if (endpointUri.getEndpointName() == null && !endpointString.equals(value.toString()))
67                 {
68                     endpoint.setName(value.toString());
69                 }
70                 return endpoint;
71             }
72             else
73             {
74                 // Global endpoints are late bound to objects because they are
75
// cloned by
76
// the Mule Manager. So e return null here and the endpoint will
77
// be set later
78
return null;
79             }
80         }
81         catch (Exception JavaDoc e)
82         {
83             throw new ConversionException(e);
84         }
85     }
86 }
87
Popular Tags