KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > components > image > ImageIOFactory


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.components.image;
18
19 import org.apache.axis.AxisProperties;
20 import org.apache.axis.components.logger.LogFactory;
21 import org.apache.axis.utils.ClassUtils;
22 import org.apache.commons.logging.Log;
23
24 /**
25  * This class implements a factory to instantiate an ImageIO component.
26  * @author <a HREF="mailto:dims@yahoo.com">Davanum Srinivas</a>
27  * @since 2.0
28  */

29 public class ImageIOFactory {
30     protected static Log log =
31             LogFactory.getLog(ImageIOFactory.class.getName());
32
33     static {
34         AxisProperties.setClassOverrideProperty(ImageIO.class, "axis.ImageIO");
35
36         // If the imageIO is not configured look for the following:
37
// 1. Try the JDK 1.4 classes
38
// 2. Try the JIMI classes
39
// 3. If all else fails, try the JDK 1.3 classes
40
AxisProperties.setClassDefaults(ImageIO.class,
41                                         new String JavaDoc [] {
42                                              "org.apache.axis.components.image.MerlinIO",
43                                              "org.apache.axis.components.image.JimiIO",
44                                              "org.apache.axis.components.image.JDK13IO",
45                                         });
46     }
47
48     /**
49      * Get the ImageIO implementation. This method follows a precedence:
50      * 1. Use the class defined by the System property axis.ImageIO.
51      * 2. If that isn't set, try instantiating MerlinIO, the JDK 1.4 ImageIO implementation.
52      * 3. If that fails try JimiIO, the JIMI ImageIO implementation.
53      * 4. If that fails, instantiate the limited JDK13IO implementation.
54      */

55     public static ImageIO getImageIO() {
56         ImageIO imageIO = (ImageIO)AxisProperties.newInstance(ImageIO.class);
57         
58         /**
59          * This shouldn't be needed, but seems to be a common feel-good:
60          */

61         if (imageIO == null) {
62             try {
63                 Class JavaDoc cls = ClassUtils.forName("org.apache.axis.components.image.JDK13IO");
64                 imageIO = (ImageIO)cls.newInstance();
65             } catch (Exception JavaDoc e) {
66                 log.debug("ImageIOFactory: No matching ImageIO found",e);
67             }
68         }
69
70         log.debug("axis.ImageIO: " + imageIO.getClass().getName());
71         return imageIO;
72     }
73 }
74
75
Popular Tags