View Javadoc

1   /*
2    * Copyright 2004-2005 Dan Washusen
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.reactive.configuration;
18  
19  import org.igfay.jfig.JFig;
20  import org.igfay.jfig.JFigException;
21  import org.igfay.jfig.JFigIF;
22  import org.igfay.jfig.JFigLocator;
23  
24  /***
25   * A wrapper for JFig configuration instantiation.  This class helps to deal with some of the oddities of JFig.
26   *
27   * <p>An example of the bean factory configuration required for JFig Configuration</p>
28   * <pre>
29   * TODO: add example XML here
30   * </pre>
31   *
32   * @author Dan Washusen
33   * @version $Id: JFigConfigurationFactory.java,v 1.2 2004/12/30 23:27:33 dan_washusen Exp $
34   * @since 30.12.2004
35   * @see org.springframework.core.io.DefaultResourceLoader
36   */
37  public class JFigConfigurationFactory {
38      private String fileName;
39      private String configLocation;
40  
41      public String getConfigLocation() {
42          return configLocation;
43      }
44  
45      public void setConfigLocation(String configLocation) {
46          this.configLocation = configLocation;
47      }
48  
49      public String getFileName() {
50          return fileName;
51      }
52  
53      /***
54       * For some reason JFig prepends the "/" character for you, even if you don't want it to.
55       * @return Returns the fixed file name (remove the "/" character if there is one)
56       */
57      public String getFixedFileName() {
58          if (getFileName().startsWith("/"))
59              return getFileName().substring(1, getFileName().length());
60          else
61              return getFileName();
62      }
63  
64      public void setFileName(String fileName) {
65          this.fileName = fileName;
66      }
67  
68      public JFigIF getConfiguration() {
69          JFigLocator jFigLocator = new JFigLocator(getFixedFileName());
70          jFigLocator.setConfigLocation(getConfigLocation());
71  
72          JFigIF jFig = null;
73          try {
74              jFig = JFig.initialize(jFigLocator);
75          } catch (JFigException e) {
76              throw new ConfigurationFactoryException("A problem was encountered while attempting to construct the JFig configuration agent.", e);
77          }
78  
79          return jFig;
80      }
81  
82  
83  //    private Resource configurationResource;
84  //
85  //    public Resource getConfigurationResource() {
86  //        return configurationResource;
87  //    }
88  //
89  //    public void setConfigurationResource(Resource configurationResource) {
90  //        this.configurationResource = configurationResource;
91  //    }
92  //
93  //    public JFigIF getConfiguration() {
94  //        JFigLocatorIF jFigLocator = null;
95  //        if (getConfigurationResource() instanceof ClassPathResource)
96  //            jFigLocator = new ClasspathResourceJFigLocator((ClassPathResource) getConfigurationResource());
97  //        else
98  //            jFigLocator = new FileSystemResourceJFigLocator((FileSystemResource) getConfigurationResource());
99  //
100 //        JFigIF jFig = JFig.getInstance(jFigLocator);
101 //
102 //        return jFig;
103 //    }
104 //
105 //    protected class ResourceJFigLocator
106 //            implements JFigLocatorIF {
107 //        protected Resource resource;
108 //        protected String configFileName;
109 //        protected String configLocation;
110 //        protected String defaultConfigFileName;
111 //
112 //        public ResourceJFigLocator(Resource resource) {
113 //            this.resource = resource;
114 //            this.configFileName = resource.
115 //        }
116 //
117 //        public Resource getResource() {
118 //            return resource;
119 //        }
120 //
121 //        public void setResource(Resource resource) {
122 //            this.resource = resource;
123 //        }
124 //
125 //        public String getConfigFileName() {
126 //            return configFileName;
127 //        }
128 //
129 //        public void setConfigFileName(String configFileName) {
130 //            this.configFileName = configFileName;
131 //        }
132 //
133 //        public String getConfigLocation() {
134 //            return configLocation;
135 //        }
136 //
137 //        public void setConfigLocation(String configLocation) {
138 //            this.configLocation = configLocation;
139 //        }
140 //
141 //        public String getDefaultConfigFileName() {
142 //            return defaultConfigFileName;
143 //        }
144 //
145 //        public void setDefaultConfigFileName(String defaultConfigFileName) {
146 //            this.defaultConfigFileName = defaultConfigFileName;
147 //        }
148 //
149 //        public InputStream getInputStream() throws JFigException {
150 //            try {
151 //                return this.resource.getInputStream();
152 //            } catch (IOException e) {
153 //                throw new JFigException(e.getMessage());
154 //            }
155 //        }
156 //    }
157 //
158 //    protected class ClasspathResourceJFigLocator
159 //            extends ResourceJFigLocator {
160 //        public static final String LOCATION = "classpath";
161 //
162 //        public ClasspathResourceJFigLocator(ClassPathResource resource) {
163 //            super(resource);
164 //            super.setConfigLocation(LOCATION);
165 //        }
166 //    }
167 //
168 //    protected class FileSystemResourceJFigLocator
169 //            extends ResourceJFigLocator {
170 //        public static final String LOCATION = "file";
171 //
172 //        public FileSystemResourceJFigLocator(FileSystemResource resource) {
173 //            super(resource);
174 //            super.setConfigLocation(LOCATION);
175 //        }
176 //    }
177 }