Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 67abf8bf33aec456119db3087abb822bcf86ff15 (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
/*******************************************************************************
 * Copyright (c) 2002, 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.wsdl.fragment.impl;

import java.util.Vector;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataException;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataParser;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.constants.FragmentConstants;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.XSDToFragmentConfiguration;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XSDEmptyFragment extends XSDFragment {
  private int occurance_;

  public XSDEmptyFragment(String id, String name, XSDToFragmentConfiguration config) {
    super(id, name, config);
    occurance_ = 0;
  }

  public boolean processParameterValues(MultipartFormDataParser parser) throws MultipartFormDataException {
    String occurance = parser.getParameter(getID());
    try {
      occurance_ = Integer.parseInt(occurance);
      return validateAllParameterValues();
    }
    catch (Throwable t) {
      occurance_ = -1;
      return false;
    }
  }

  public void setParameterValues(String paramKey, String[] params) {
  }

  public void setParameterValues(String paramKey, Vector params) {
  }

  public String[] getParameterValues(String paramKey) {
    if (occurance_ < 0)
      return null;
    else {
      String[] params = new String[occurance_];
      for (int i = 0; i < params.length; i++) {
        params[i] = "";
      }
      return params;
    }
  }

  public String getParameterValue(String paramKey, int paramIndex) {
    if (paramIndex >= 0 && paramIndex < occurance_)
      return "";
    else
      return null;
  }

  public boolean validateAllParameterValues() {
    XSDToFragmentConfiguration xsdConfig = getXSDToFragmentConfiguration();
    int min = xsdConfig.getMinOccurs();
    int max = xsdConfig.getMaxOccurs();
    return (occurance_ >= 0 && occurance_ >= min && (max == FragmentConstants.UNBOUNDED || occurance_ <= max));
  }

  public boolean validateParameterValues(String paramKey) {
    return validateAllParameterValues();
  }

  public boolean validateParameterValue(String paramKey, int paramIndex) {
    return validateAllParameterValues();
  }

  public boolean setParameterValuesFromInstanceDocuments(Element[] instanceDocuments) {
    Element[] instanceDocumentsCopy = getInstanceDocumentsByTagName(instanceDocuments, getName());
    boolean paramsValid = true;
    for (int i = 0; i < instanceDocumentsCopy.length; i++) {
      NodeList nodeList = instanceDocumentsCopy[i].getChildNodes();
      if (nodeList.getLength() > 1)
        paramsValid = false;
      else if (nodeList.getLength() != 0) {
        Node node = nodeList.item(0);
        if (node.getNodeType() != Node.TEXT_NODE || !isWhitespace(node.getNodeValue()))
          paramsValid = false;
      }
    }
    occurance_ = instanceDocumentsCopy.length;
    return paramsValid && validateAllParameterValues();
  }

  private boolean isWhitespace(String s) {
    char[] chars = s.toCharArray();
    for (int i = 0; i < chars.length; i++) {
      if (!Character.isWhitespace(chars[i]) || !Character.isSpaceChar(chars[i]))
        return false;
    }
    return true;
  }

  public String getInformationFragment() {
    return "/wsdl/fragment/XSDDefaultInfoFragmentJSP.jsp";
  }

  public String getWriteFragment() {
    return "/wsdl/fragment/XSDEmptyWFragmentJSP.jsp";
  }

  public String getReadFragment() {
    return "/wsdl/fragment/XSDEmptyRFragmentJSP.jsp";
  }
}

Back to the top