001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.catalog.ui.workflow;
016:
017: import java.io.IOException;
018: import java.io.Serializable;
019: import java.net.URL;
020: import java.util.ArrayList;
021: import java.util.Collections;
022: import java.util.HashMap;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.eclipse.core.runtime.IConfigurationElement;
027: import org.eclipse.core.runtime.IProgressMonitor;
028:
029: import net.refractions.udig.catalog.ServiceExtension;
030: import net.refractions.udig.catalog.ServiceExtension2;
031: import net.refractions.udig.catalog.ui.internal.Messages;
032: import net.refractions.udig.catalog.ui.workflow.Workflow.State;
033: import net.refractions.udig.core.internal.ExtensionPointList;
034:
035: /**
036: * A State that will occur if no services were able to be created from a param map or a URL. This state is designed
037: * to explain "why" the failure occurred.
038: *
039: * @author Jesse
040: * @since 1.1.0
041: */
042: public class ConnectionFailureState extends State {
043:
044: private Map<String, Serializable> params;
045: private List<URL> urls;
046: private Map<String, List<Data>> reports = new HashMap<String, List<Data>>();
047:
048: public ConnectionFailureState(List<URL> urls,
049: Map<String, Serializable> params) {
050: if (params == null) {
051: this .urls = urls;
052: if (urls != null && urls.isEmpty())
053: this .urls = null;
054: } else
055: this .params = params;
056: }
057:
058: @Override
059: public String getName() {
060: return Messages.ConnectionFailureState_name;
061: }
062:
063: public Map<String, Serializable> getParams() {
064: return params;
065: }
066:
067: public List<URL> getUrls() {
068: return urls;
069: }
070:
071: public Map<String, List<Data>> getReports() {
072: return reports;
073: }
074:
075: @Override
076: public void init(IProgressMonitor monitor) throws IOException {
077:
078: if (params == null && urls == null) {
079: reports
080: .put(
081: "msg", Collections.singletonList(new Data("msg", "No Connection Information", "For some reason the previous wizard page did not"))); //$NON-NLS-1$ //$NON-NLS-2$
082: return;
083: }
084:
085: List<IConfigurationElement> list = ExtensionPointList
086: .getExtensionPointList(ServiceExtension.EXTENSION_ID);
087: for (IConfigurationElement element : list) {
088: List<Data> data = new ArrayList<Data>();
089:
090: String id = element.getNamespaceIdentifier().toString()
091: + "." + element.getAttribute("id"); //$NON-NLS-1$ //$NON-NLS-2$
092: String name = element.getAttribute("name"); //$NON-NLS-1$
093: if (name == null) {
094: name = element.getAttribute("id"); //$NON-NLS-1$
095: }
096:
097: try {
098: ServiceExtension extension = (ServiceExtension) element
099: .createExecutableExtension("class"); //$NON-NLS-1$
100: if (extension instanceof ServiceExtension2) {
101: ServiceExtension2 e2 = (ServiceExtension2) extension;
102: if (params != null) {
103: data.add(new Data(id, name, e2
104: .reasonForFailure(params)));
105: } else {
106: for (URL url : urls) {
107: data.add(new Data(id, name, e2
108: .reasonForFailure(url), url));
109: }
110: }
111: }
112: if (data.isEmpty())
113: data
114: .add(new Data(id, name,
115: "Implementation does not provide any debug information"));
116:
117: } catch (Throwable e) {
118: data.add(new Data(id, name, e.getLocalizedMessage()));
119: }
120: reports.put(id, data);
121: }
122: }
123:
124: @Override
125: public boolean run(IProgressMonitor monitor) throws IOException {
126: return false;
127: }
128:
129: class Data {
130:
131: String message;
132: String name;
133: URL url;
134: String id;
135:
136: public Data(String id, String name, String message) {
137: if (id == null)
138: throw new NullPointerException();
139: if (name == null)
140: throw new NullPointerException();
141: this .name = name;
142: this .message = message;
143: this .id = id;
144: }
145:
146: public Data(String id, String name2, String string, URL url) {
147: this (id, name2, string);
148: if (url == null)
149: throw new NullPointerException();
150: this.url = url;
151: }
152:
153: }
154: }
|