KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > pos > jpos > factory > OfbizJposServiceFactory


1 /*
2  * $Id: OfbizJposServiceFactory.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.pos.jpos.factory;
26
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import jpos.JposConst;
31 import jpos.JposException;
32 import jpos.config.JposEntry;
33 import jpos.loader.JposServiceInstance;
34 import jpos.loader.JposServiceInstanceFactory;
35
36 import org.ofbiz.base.util.ObjectType;
37 import org.ofbiz.pos.jpos.service.BaseService;
38
39 /**
40  *
41  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
42  * @version $Rev: 5462 $
43  * @since 3.2
44  */

45 public class OfbizJposServiceFactory extends Object JavaDoc implements JposServiceInstanceFactory {
46
47     public static final String JavaDoc module = OfbizJposServiceFactory.class.getName();
48     private static Map JavaDoc serviceMap = new HashMap JavaDoc();
49
50     public JposServiceInstance createInstance(String JavaDoc logicalName, JposEntry entry) throws JposException {
51         // check to see if we have a service class property
52
if (!entry.hasPropertyWithName(JposEntry.SERVICE_CLASS_PROP_NAME)) {
53             throw new JposException(JposConst.JPOS_E_NOSERVICE, "serviceClass property not found!");
54         }
55
56         String JavaDoc className = (String JavaDoc) entry.getPropertyValue(JposEntry.SERVICE_CLASS_PROP_NAME);
57         BaseService service = (BaseService) serviceMap.get(className);
58
59         if (service != null) {
60             service.setEntry(entry);
61         } else {
62             try {
63                 Object JavaDoc obj = ObjectType.getInstance(className);
64                 if (obj == null) {
65                     throw new JposException(JposConst.JPOS_E_NOEXIST, "unable to locate serviceClass");
66                 }
67
68                 if (!(obj instanceof JposServiceInstance)) {
69                     throw new JposException(JposConst.JPOS_E_NOSERVICE, "serviceClass is not an instance of JposServiceInstance");
70                 } else if (!(obj instanceof BaseService)) {
71                     throw new JposException(JposConst.JPOS_E_NOSERVICE, "serviceClass is not an instance of BaseKybService");
72                 } else {
73                     service = (BaseService) obj;
74                     service.setEntry(entry);
75                     serviceMap.put(className, service);
76                 }
77             } catch (Exception JavaDoc e) {
78                 throw new JposException(JposConst.JPOS_E_NOSERVICE, "Error creating the service instance [" + className + "]", e);
79             }
80         }
81
82         return service;
83     }
84 }
85
Popular Tags