001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)FileBindingResolver.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.file;
030:
031: import org.w3c.dom.Document;
032:
033: import java.util.Hashtable;
034:
035: import javax.jbi.servicedesc.ServiceEndpoint;
036:
037: import javax.xml.parsers.DocumentBuilderFactory;
038:
039: /**
040: * This class implements the Resolver contract with the NMR. Resolver is used
041: * by other components of JBI to query meta-data of endpoints deployed in file
042: * binding.
043: *
044: * @author Sun Microsystems, Inc.
045: */
046: public class FileBindingResolver {
047: /**
048: * Holds the descriptor objects.
049: */
050: private Hashtable mDescriptorCache;
051:
052: /**
053: * Creates a new FileBindingResolver object.
054: */
055: public FileBindingResolver() {
056: mDescriptorCache = new Hashtable();
057: }
058:
059: /**
060: * Contract with framework. This method is used by other components to
061: * query meta-data.
062: *
063: * @param ef endpoint reference.
064: *
065: * @return descriptor object.
066: */
067: public Document getServiceDescription(ServiceEndpoint ef) {
068: try {
069: Document df = (Document) mDescriptorCache.get(ef
070: .getServiceName().toString()
071: + ef.getEndpointName());
072:
073: return df;
074: } catch (Exception e) {
075: return null;
076: }
077: }
078:
079: /**
080: * Adds endpoint meta-data.
081: *
082: * @param epname endpoint name.
083: * @param df document fragment.
084: */
085: public void addEndpointDoc(String epname, Document df) {
086: if ((epname != null) && (df != null)) {
087: try {
088: mDescriptorCache.put(epname, df);
089: } catch (Exception e) {
090: e.printStackTrace();
091: }
092: }
093: }
094:
095: /**
096: * Adds an endpoint document.
097: *
098: * @param epname endpoint name.
099: * @param filename wsdl file.
100: */
101: public void addEndpointDoc(String epname, String filename) {
102: if ((epname != null) && (filename != null)) {
103: try {
104: org.w3c.dom.Document d = DocumentBuilderFactory
105: .newInstance().newDocumentBuilder().parse(
106: filename);
107: mDescriptorCache.put(epname, d);
108: } catch (Exception e) {
109: e.printStackTrace();
110: }
111: }
112: }
113:
114: /**
115: * Clears the descriptor cache. Removes all information.
116: */
117: public void clearCache() {
118: mDescriptorCache = new Hashtable();
119: }
120: }
|