Skip to main content
summaryrefslogtreecommitdiffstats
blob: 375510e49892f5c75347c09a96b229f04e425179 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************************
 * Copyright (c) 2002, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060216   127138 pmoogk@ca.ibm.com - Peter Moogk
 *******************************************************************************/

package org.eclipse.jst.ws.internal.uddiregistry.wizard;

import java.util.Vector;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import com.ibm.icu.util.StringTokenizer;

public class PrivateUDDIRegistryTypeRegistry {

    private static PrivateUDDIRegistryTypeRegistry instance_;
    private IConfigurationElement[] configElements_;

    private PrivateUDDIRegistryTypeRegistry() {
    }
  
    /**
    * Returns a singleton instance of this class.
    * @return A singleton WebServiceClientTypeRegistry object.
    */
    public static PrivateUDDIRegistryTypeRegistry getInstance() {
        if (instance_ == null) {
            instance_ = new PrivateUDDIRegistryTypeRegistry();
            instance_.getConfigElements();
        }
        return instance_;
    }
  
    public IConfigurationElement[] getConfigElements() {
        IExtensionRegistry reg = Platform.getExtensionRegistry();
        configElements_ = reg.getConfigurationElementsFor(
                                     "org.eclipse.jst.ws.uddiregistry",
                                     "privateUDDIRegistryType");
        Vector v = new Vector();
        for (int i = 0; i < configElements_.length; i++)
        {
          int weight = getWeight(configElements_[i]);
          int index = -1;
          for (int j = v.size()-1; j >= 0; j--)
          {
            if (weight > getWeight((IConfigurationElement)v.get(j)))
              index = j;
            else
              break;
          }
          if (index != -1)
            v.add(index, configElements_[i]);
          else
            v.add(configElements_[i]);
        }
        v.copyInto(configElements_);
        return configElements_;
    }

    private int getWeight(IConfigurationElement e)
    {
      try
      {
        return Integer.parseInt(e.getAttribute("weight"));
      }
      catch (NumberFormatException nfe)
      {
        return -1;
      }
    }

    private IConfigurationElement getConfigElementByID(String id) {
        for (int i = 0; i <configElements_.length; i++) {
            if (configElements_[i].getAttribute("id").equals(id))
                return configElements_[i];
        }
        return null;
    }

    public PrivateUDDIRegistryType[] getTypes() {
        Vector types = new Vector();
        for (int i = 0; i < configElements_.length; i++) {
            try {
                Object typeObj = configElements_[i].createExecutableExtension("class");
                if (typeObj instanceof PrivateUDDIRegistryType)
                    types.add(typeObj);
            }
            catch (Exception e) {}
        }

        PrivateUDDIRegistryType[] typesArray = new PrivateUDDIRegistryType[types.size()];
        for (int j = 0; j < types.size(); j++) {
            typesArray[j] = (PrivateUDDIRegistryType)types.elementAt(j);
        }
        return typesArray;
    }

    public PrivateUDDIRegistryType getTypeByID(String id) {
        try {
            Object typeObj = getConfigElementByID(id).createExecutableExtension("class");
            if (typeObj instanceof PrivateUDDIRegistryType)
                return (PrivateUDDIRegistryType)typeObj; 
        }
        catch (Exception e) {}
        return null;
    }

    public String[] getSupportedServerFactoryIDByID(String id) {
        IConfigurationElement configElement = getConfigElementByID(id);
        if (configElement == null)
            return new String[0];
        Vector idVector = new Vector();
        StringTokenizer st = new StringTokenizer(configElement.getAttribute("serverFactoryID"), ",");
        while (st.hasMoreTokens()) {
            idVector.add(st.nextToken());
        }
        String[] ids = new String[idVector.size()];
        for (int i = 0; i < idVector.size(); i++) {
            ids[i] = (String)idVector.elementAt(i);
        }
        return ids;
    }

}

Back to the top