01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19:
20: package org.netbeans.modules.xml.xpath.ext;
21:
22: /**
23: * XPathModel helper class.
24: *
25: * @author Enrico Lelina
26: * @version
27: */
28: public abstract class XPathModelHelper {
29:
30: /** Singleton Castor support */
31: private static XPathModelHelper mXPathModelHelper = null;
32:
33: /**
34: * Get Castor support from Enterprise Designer context.
35: * @return AbstractXPathModelHelper The castor support object.
36: */
37: public static synchronized XPathModelHelper getInstance() {
38: if (mXPathModelHelper == null) {
39: mXPathModelHelper = loadImpl(null);
40: }
41:
42: return mXPathModelHelper;
43: }
44:
45: /**
46: * Get the Castor support using the given Class Loader.
47: * @param loader Class Loader that can find the XPathModelHelper
48: * implementation class.
49: * @return AbstractCastorSuppport The castor support object.
50: */
51: public static synchronized XPathModelHelper getInstance(
52: ClassLoader loader) {
53: if (null == mXPathModelHelper) {
54: mXPathModelHelper = loadImpl(loader);
55: }
56: return mXPathModelHelper;
57: }
58:
59: /** Loads the XPathModelHelper implementation class.
60: * @param loader ClassLoader to use.
61: * @return XPathModelHelper implementing class.
62: */
63: private static XPathModelHelper loadImpl(ClassLoader loader) {
64: String implClassName = null;
65: XPathModelHelper axmh = null;
66: try {
67: implClassName = System
68: .getProperty(
69: "org.netbeans.modules.xml.xpath.ext.XPathModelHelper",
70: "org.netbeans.modules.xml.xpath.ext.impl.XPathModelHelperImpl");
71: Class implClass = null;
72: if (loader != null) {
73: implClass = Class.forName(implClassName, true, loader);
74: } else {
75: implClass = Class.forName(implClassName);
76: }
77: axmh = (XPathModelHelper) implClass.newInstance();
78: } catch (Exception e) {
79: throw new IllegalArgumentException("Cannot find/load "
80: + implClassName, e);
81: }
82: return axmh;
83: }
84:
85: /**
86: * Instantiates a new XPathModel object.
87: * @return a new XPathModel object instance
88: */
89: public abstract XPathModel newXPathModel();
90:
91: }
|