001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.planner;
017:
018: import java.io.*;
019: import java.util.*;
020:
021: import org.griphyn.common.util.*;
022: import org.griphyn.common.classes.TCType;
023: import org.griphyn.common.catalog.transformation.TCMode;
024: import org.griphyn.common.catalog.TransformationCatalog;
025: import org.griphyn.common.catalog.TransformationCatalogEntry;
026:
027: /**
028: * This class wraps the shell planner's request into the new TC API.
029: *
030: * @author Jens-S. Vöckler
031: * @author Yong Zhao
032: * @version $Revision: 50 $
033: *
034: */
035: public class TCWrapper implements Wrapper {
036: /**
037: * transformation catalog API reference.
038: */
039: private TransformationCatalog m_tc;
040:
041: /**
042: * Connects the interface with the transformation catalog
043: * implementation. The choice of backend is configured through
044: * properties.
045: */
046: public TCWrapper() {
047: m_tc = TCMode.loadInstance();
048: }
049:
050: /**
051: * Frees resources taken by the instance of the replica catalog. This
052: * method is safe to be called on failed or already closed catalogs.
053: */
054: public void close() {
055: if (m_tc != null) {
056: m_tc.close();
057: m_tc = null;
058: }
059: }
060:
061: /**
062: * garbage collection.
063: */
064: protected void finalize() {
065: close();
066: }
067:
068: /**
069: * Obtains all applications that bear the name and are installed at the
070: * resource.
071: *
072: * @param ns is the TR namespace
073: * @param id is the TR identifier
074: * @param vs is the TR version
075: * @param site is the site handle, should be "local".
076: * @return a possibly empty list of
077: * {@link org.griphyn.common.catalog.TransformationCatalogEntry TransformationCatalogEntry} with all matches.
078: */
079: public List lookup(String ns, String id, String vs, String site) {
080: // sanity check
081: if (m_tc == null)
082: return null;
083:
084: List result = null;
085: try {
086: result = m_tc.getTCEntries(ns, id, vs, site,
087: TCType.INSTALLED);
088: } catch (Exception e) {
089: result = null;
090: }
091:
092: return result;
093: }
094:
095: /**
096: * Extracts all profiles contained in the transformation catalog entry.
097: *
098: * @param tce is the transformation catalog entry
099: * @return a map of maps. The outer map is indexed by the lower-cased
100: * namespace identifier. The inner map is indexed by the key within
101: * the particular namespace. An empty map is possible.
102: */
103: public static Map getProfiles(TransformationCatalogEntry tce) {
104: Map result = new HashMap();
105: List lop = tce.getProfiles();
106: if (lop == null || lop.size() == 0)
107: return result;
108:
109: Map submap = null;
110: for (Iterator i = lop.iterator(); i.hasNext();) {
111: org.griphyn.cPlanner.classes.Profile p = (org.griphyn.cPlanner.classes.Profile) i
112: .next();
113: String ns = p.getProfileNamespace().trim().toLowerCase();
114: String key = p.getProfileKey().trim();
115: String value = p.getProfileValue();
116:
117: // insert at the right place into the result map
118: if (result.containsKey(ns)) {
119: submap = (Map) result.get(ns);
120: } else {
121: result.put(ns, (submap = new HashMap()));
122: }
123: submap.put(key, value);
124: }
125:
126: return result;
127: }
128:
129: /**
130: * Obtains the name of the class implementing the replica catalog.
131: *
132: * @return class name of the replica catalog implementor.
133: */
134: public String getName() {
135: return (m_tc == null ? null : m_tc.getClass().getName());
136: }
137:
138: /**
139: * Shows the contents of the catalog as one string.
140: *
141: * @return the string with the complete catalog contents. Warning,
142: * this may be very large, slow, and memory expensive.
143: */
144: public String toString() {
145: return "(method not implemented)";
146: }
147: }
|