1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.internal.ws.wsdl.document;
27
28 import com.sun.tools.internal.ws.wsdl.framework.*;
29 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
30 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
31
32 import javax.xml.namespace.QName;
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.Set;
36
37 /**
38 * A WSDL document.
39 *
40 * @author WS Development Team
41 */
42 public class WSDLDocument extends AbstractDocument{
43
44 public WSDLDocument(MetadataFinder forest, ErrorReceiver errReceiver) {
45 super(forest, errReceiver);
46 }
47
48 public Definitions getDefinitions() {
49 return _definitions;
50 }
51
52 public void setDefinitions(Definitions d) {
53 _definitions = d;
54 }
55
93 for (Iterator iter = getDefinitions().services(); iter.hasNext();) {
94 Service next = (Service) iter.next();
95 if (next.getName().equals(serviceNameLocalPart)) {
96 for (Iterator piter = next.ports(); piter.hasNext();) {
97 Port pnext = (Port) piter.next();
98 String targetNamespace =
99 pnext.getDefining().getTargetNamespaceURI();
100 String localName = pnext.getName();
101 QName portQName = new QName(targetNamespace, localName);
102 portQNames.add(portQName);
103 }
104 }
105 }
106 return (QName[]) portQNames.toArray(new QName[portQNames.size()]);
107 }
108
109 public void accept(WSDLDocumentVisitor visitor) throws Exception {
110 _definitions.accept(visitor);
111 }
112
113 public void validate(EntityReferenceValidator validator) {
114 GloballyValidatingAction action =
115 new GloballyValidatingAction(this, validator);
116 withAllSubEntitiesDo(action);
117 if (action.getException() != null) {
118 throw action.getException();
119 }
120 }
121
122 protected Entity getRoot() {
123 return _definitions;
124 }
125
126 private Definitions _definitions;
127
128 private class GloballyValidatingAction
129 implements EntityAction, EntityReferenceAction {
130 public GloballyValidatingAction(
131 AbstractDocument document,
132 EntityReferenceValidator validator) {
133 _document = document;
134 _validator = validator;
135 }
136
137 public void perform(Entity entity) {
138 try {
139 entity.validateThis();
140 entity.withAllEntityReferencesDo(this);
141 entity.withAllSubEntitiesDo(this);
142 } catch (ValidationException e) {
143 if (_exception == null) {
144 _exception = e;
145 }
146 }
147 }
148
149 public void perform(Kind kind, QName name) {
150 try {
151 GloballyKnown entity = _document.find(kind, name);
152 } catch (NoSuchEntityException e) {
153 // failed to resolve, check with the validator
154 if (_exception == null) {
155 if (_validator == null
156 || !_validator.isValid(kind, name)) {
157 _exception = e;
158 }
159 }
160 }
161 }
162
163 public ValidationException getException() {
164 return _exception;
165 }
166
167 private ValidationException _exception;
168 private AbstractDocument _document;
169 private EntityReferenceValidator _validator;
170 }
171 }
|
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.internal.ws.wsdl.document;
27
28 import com.sun.tools.internal.ws.wsdl.framework.*;
29 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
30 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
31
32 import javax.xml.namespace.QName;
33 import java.util.ArrayList;
34 import java.util.Iterator;
35
36 /**
37 * A WSDL document.
38 *
39 * @author WS Development Team
40 */
41 public class WSDLDocument extends AbstractDocument{
42
43 public WSDLDocument(MetadataFinder forest, ErrorReceiver errReceiver) {
44 super(forest, errReceiver);
45 }
46
47 public Definitions getDefinitions() {
48 return _definitions;
49 }
50
51 public void setDefinitions(Definitions d) {
52 _definitions = d;
53 }
54
92 for (Iterator iter = getDefinitions().services(); iter.hasNext();) {
93 Service next = (Service) iter.next();
94 if (next.getName().equals(serviceNameLocalPart)) {
95 for (Iterator piter = next.ports(); piter.hasNext();) {
96 Port pnext = (Port) piter.next();
97 String targetNamespace =
98 pnext.getDefining().getTargetNamespaceURI();
99 String localName = pnext.getName();
100 QName portQName = new QName(targetNamespace, localName);
101 portQNames.add(portQName);
102 }
103 }
104 }
105 return (QName[]) portQNames.toArray(new QName[portQNames.size()]);
106 }
107
108 public void accept(WSDLDocumentVisitor visitor) throws Exception {
109 _definitions.accept(visitor);
110 }
111
112 @Override
113 public void validate(EntityReferenceValidator validator) {
114 GloballyValidatingAction action =
115 new GloballyValidatingAction(this, validator);
116 withAllSubEntitiesDo(action);
117 if (action.getException() != null) {
118 throw action.getException();
119 }
120 }
121
122 @Override
123 protected Entity getRoot() {
124 return _definitions;
125 }
126
127 private Definitions _definitions;
128
129 private static class GloballyValidatingAction implements EntityAction, EntityReferenceAction {
130 public GloballyValidatingAction(
131 AbstractDocument document,
132 EntityReferenceValidator validator) {
133 _document = document;
134 _validator = validator;
135 }
136
137 @Override
138 public void perform(Entity entity) {
139 try {
140 entity.validateThis();
141 entity.withAllEntityReferencesDo(this);
142 entity.withAllSubEntitiesDo(this);
143 } catch (ValidationException e) {
144 if (_exception == null) {
145 _exception = e;
146 }
147 }
148 }
149
150 @Override
151 public void perform(Kind kind, QName name) {
152 try {
153 _document.find(kind, name);
154 } catch (NoSuchEntityException e) {
155 // failed to resolve, check with the validator
156 if (_exception == null) {
157 if (_validator == null
158 || !_validator.isValid(kind, name)) {
159 _exception = e;
160 }
161 }
162 }
163 }
164
165 public ValidationException getException() {
166 return _exception;
167 }
168
169 private ValidationException _exception;
170 private AbstractDocument _document;
171 private EntityReferenceValidator _validator;
172 }
173 }
|