001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.automation;
028:
029: import java.util.*;
030: import com.sun.midp.main.*;
031:
032: /**
033: * AutoMIDletInfo list
034: */
035: class AutoMIDletInfoList {
036: /** Vector of AutoMIDletInfo objects */
037: private Vector midletsInfo;
038:
039: /** The one and only instance of AutoMIDletInfoList */
040: private static AutoMIDletInfoList midletInfoList = null;
041:
042: /**
043: * Private constructor to prevent direct creation of instances.
044: */
045: AutoMIDletInfoList() {
046: midletsInfo = new Vector();
047: }
048:
049: /**
050: * Gets AutoMIDletInfoList instance.
051: *
052: * @return AutoMIDletInfoList instance
053: */
054: synchronized static AutoMIDletInfoList getMIDletInfoList() {
055: if (midletInfoList == null) {
056: midletInfoList = new AutoMIDletInfoList();
057: }
058:
059: return midletInfoList;
060: }
061:
062: /**
063: * Creates AutoMIDletInfo and adds it to the list.
064: *
065: * @param suiteID suite ID
066: * @param midletClassName MIDlet's class name
067: * @return created AutoMIDletInfo instance
068: */
069: AutoMIDletInfo addToList(int suiteID, String midletClassName) {
070: synchronized (this ) {
071: AutoMIDletInfo info = new AutoMIDletInfo(suiteID,
072: midletClassName);
073: midletsInfo.addElement(info);
074:
075: return info;
076: }
077: }
078:
079: /**
080: * Finds MIDlet info by MIDlet's suite ID and class name.
081: *
082: * @param suiteID suite ID
083: * @param midletClassName MIDlet's class name
084: * @return corresponding AutoMIDletInfo instance or null,
085: * if it hasn't been found
086: */
087: AutoMIDletInfo findMIDletInfo(int suiteID, String midletClassName) {
088: synchronized (this ) {
089: for (int i = 0; i < midletsInfo.size(); ++i) {
090: AutoMIDletInfo info = (AutoMIDletInfo) midletsInfo
091: .elementAt(i);
092: if (info.suiteID == suiteID
093: && info.midletClassName.equals(midletClassName)) {
094: return info;
095: }
096: }
097: }
098:
099: return null;
100: }
101:
102: /**
103: * Finds MIDlet info by AutoMIDletImpl.
104: *
105: * @param midlet AutoMIDletImpl reference to be used as key
106: * @return corresponding AutoMIDletInfo instance or null,
107: * if it hasn't been found
108: */
109: AutoMIDletInfo findMIDletInfo(AutoMIDletImpl midlet) {
110: synchronized (this ) {
111: for (int i = 0; i < midletsInfo.size(); ++i) {
112: AutoMIDletInfo info = (AutoMIDletInfo) midletsInfo
113: .elementAt(i);
114: if (info.midlet == midlet) {
115: return info;
116: }
117: }
118: }
119:
120: return null;
121: }
122:
123: /**
124: * Finds MIDlet info by MIDletProxy.
125: *
126: * @param midletProxy MIDletProxy reference to be used as key
127: * @return corresponding AutoMIDletInfo instance or null,
128: * if it hasn't been found
129: */
130: AutoMIDletInfo findMIDletInfo(MIDletProxy midletProxy) {
131: AutoMIDletInfo info = findMIDletInfo(midletProxy.getSuiteId(),
132: midletProxy.getClassName());
133:
134: return info;
135: }
136:
137: /**
138: * Finds AutoMIDlet corresponding to specified MIDletProxy.
139: *
140: * @param midletProxy MIDletProxy instance
141: * @return AutoMIDletImpl instance corresponding to MIDletProxy,
142: * or null if it hasn't been found
143: */
144: AutoMIDletImpl findMIDlet(MIDletProxy midletProxy) {
145: AutoMIDletImpl midlet = null;
146: AutoMIDletInfo info = findMIDletInfo(midletProxy);
147: if (info != null) {
148: midlet = info.midlet;
149: }
150:
151: return midlet;
152: }
153:
154: /**
155: * Finds MIDletProxy corresponding to specified AutoMIDlet
156: *
157: * @param midlet AutoMIDletImpl instance
158: * @return MIDletProxy instance corresponding to AutoMIDletImpl,
159: * or null if it hasn't been found
160: */
161: MIDletProxy findMIDletProxy(AutoMIDletImpl midlet) {
162: MIDletProxy midletProxy = null;
163: AutoMIDletInfo info = findMIDletInfo(midlet);
164: if (info != null) {
165: midletProxy = info.midletProxy;
166: }
167:
168: return midletProxy;
169: }
170:
171: /**
172: * Removes specified AutoMIDletInfo instance from list.
173: *
174: * @param info AutoMIDletInfo instance to be removed
175: */
176: void removeFromList(AutoMIDletInfo info) {
177: midletsInfo.removeElement(info);
178: }
179: }
|