Skip to main content
summaryrefslogtreecommitdiffstats
blob: 182d33ab13e26d23c051883dade7ef0ce1f10d6d (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
/*******************************************************************************
 * Copyright (c) 2001, 2004 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
 *******************************************************************************/

package org.eclipse.wst.ws.internal.explorer.platform.wsil.datamodel;

import org.apache.wsil.Link;
import org.apache.wsil.extension.ExtensionElement;
import org.apache.wsil.extension.uddi.BusinessDescription;
import org.eclipse.wst.ws.internal.datamodel.Model;
import org.eclipse.wst.ws.internal.explorer.platform.util.Validator;
import org.uddi4j.datatype.business.BusinessEntity;
import org.uddi4j.util.DiscoveryURL;

/**
* The data model element that represents 
* a UDDI service in a WSIL document
*/
public class WsilUddiBusinessElement extends WsilLinkElement
{
    private BusinessEntity busEntity_;

    public WsilUddiBusinessElement(String name, Model model, Link link) {
        super(name, model, link);
        busEntity_ = null;
    }

    public void setServiceProvider(BusinessEntity be) {
      busEntity_ = be;
    }

    public BusinessEntity getServiceProvider() {
        return busEntity_;
    }

    public String getName() {
        return (busEntity_  == null) ? null : busEntity_.getDefaultNameString();
    }

    public String getDescription() {
        return (busEntity_ == null) ? null : busEntity_.getDefaultDescriptionString();
    }

    public String getUDDILinkInquiryAPI() {
        BusinessDescription bd = getValidUDDIBusinessDescription();
        return (bd == null) ? null : bd.getLocation();
    }

    public String getUDDILinkBusinessKey() {
        BusinessDescription bd = getValidUDDIBusinessDescription();
        return (bd == null) ? null : bd.getBusinessKey().getText();
    }

    public String getUDDILinkDiscoveryURL() {
        BusinessDescription bd = getValidUDDIBusinessDescription();
        if (bd == null)
            return null;
        else {
            DiscoveryURL discoveryURL = bd.getDiscoveryURL();
            return (discoveryURL == null) ? null : discoveryURL.getText();
        }
    }

    public boolean validateUDDILink() {
        BusinessDescription bd = getValidUDDIBusinessDescription();
        return (bd != null);
    }

    private BusinessDescription getValidUDDIBusinessDescription() {
        ExtensionElement extElement = link_.getExtensionElement();
        // The extension element of a UDDI link
        // must be a BusinessDescription element
        if (!(extElement instanceof BusinessDescription))
            return null;
        // A valid BusinessDescription must have an inquiry API
        String inquiryAPI = ((BusinessDescription)extElement).getLocation();
        if (!Validator.validateURL(inquiryAPI))
            return null;
        // A valid BusinessDescription must have a business key
        String businessKey = ((BusinessDescription)extElement).getBusinessKey().getText();
        if (businessKey == null || businessKey.length() <= 0)
            return null;
        return (BusinessDescription)extElement;
    }

    public String toString() {
        return getName();
    }
}

Back to the top