src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/framework/AbstractDocument.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/framework/AbstractDocument.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,186 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.ws.wsdl.framework;
    1.30 +
    1.31 +import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
    1.32 +import com.sun.tools.internal.ws.wsdl.parser.DOMForest;
    1.33 +import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
    1.34 +import com.sun.tools.internal.ws.wscompile.AbortException;
    1.35 +import com.sun.tools.internal.ws.resources.WsdlMessages;
    1.36 +
    1.37 +import javax.xml.namespace.QName;
    1.38 +import java.util.*;
    1.39 +
    1.40 +/**
    1.41 + * An abstract class for documents containing entities.
    1.42 + *
    1.43 + * @author WS Development Team
    1.44 + */
    1.45 +public abstract class AbstractDocument {
    1.46 +
    1.47 +    protected final DOMForest forest;
    1.48 +    protected final ErrorReceiver errReceiver;
    1.49 +
    1.50 +    protected AbstractDocument(MetadataFinder forest, ErrorReceiver errReceiver) {
    1.51 +        this.forest = forest;
    1.52 +        this.errReceiver = errReceiver;
    1.53 +        kinds = new HashMap();
    1.54 +        importedEntities = new ArrayList();
    1.55 +        importedDocuments = new HashSet();
    1.56 +        includedEntities = new ArrayList();
    1.57 +        includedDocuments = new HashSet();
    1.58 +    }
    1.59 +
    1.60 +    public String getSystemId() {
    1.61 +        return _systemId;
    1.62 +    }
    1.63 +
    1.64 +    public void setSystemId(String s) {
    1.65 +        if (_systemId != null && !_systemId.equals(s)) {
    1.66 +            // avoid redefinition of a system identifier
    1.67 +            throw new IllegalArgumentException();
    1.68 +        }
    1.69 +
    1.70 +        _systemId = s;
    1.71 +        if (s != null) {
    1.72 +            importedDocuments.add(s);
    1.73 +        }
    1.74 +    }
    1.75 +
    1.76 +    public void addIncludedDocument(String systemId) {
    1.77 +        includedDocuments.add(systemId);
    1.78 +    }
    1.79 +
    1.80 +    public boolean isIncludedDocument(String systemId) {
    1.81 +        return includedDocuments.contains(systemId);
    1.82 +    }
    1.83 +
    1.84 +    public void addIncludedEntity(Entity entity) {
    1.85 +        includedEntities.add(entity);
    1.86 +    }
    1.87 +
    1.88 +    public void addImportedDocument(String systemId) {
    1.89 +        importedDocuments.add(systemId);
    1.90 +    }
    1.91 +
    1.92 +    public boolean isImportedDocument(String systemId) {
    1.93 +        return importedDocuments.contains(systemId);
    1.94 +    }
    1.95 +
    1.96 +    public void addImportedEntity(Entity entity) {
    1.97 +        importedEntities.add(entity);
    1.98 +    }
    1.99 +
   1.100 +    public void withAllSubEntitiesDo(EntityAction action) {
   1.101 +        if (getRoot() != null) {
   1.102 +            action.perform(getRoot());
   1.103 +        }
   1.104 +
   1.105 +        for (Iterator iter = importedEntities.iterator(); iter.hasNext();) {
   1.106 +            action.perform((Entity) iter.next());
   1.107 +        }
   1.108 +
   1.109 +        for (Iterator iter = includedEntities.iterator(); iter.hasNext();) {
   1.110 +            action.perform((Entity) iter.next());
   1.111 +        }
   1.112 +    }
   1.113 +
   1.114 +    public Map getMap(Kind k) {
   1.115 +        Map m = (Map) kinds.get(k.getName());
   1.116 +        if (m == null) {
   1.117 +            m = new HashMap();
   1.118 +            kinds.put(k.getName(), m);
   1.119 +        }
   1.120 +        return m;
   1.121 +    }
   1.122 +
   1.123 +    public void define(GloballyKnown e) {
   1.124 +        Map map = getMap(e.getKind());
   1.125 +        if (e.getName() == null)
   1.126 +            return;
   1.127 +        QName name =
   1.128 +            new QName(e.getDefining().getTargetNamespaceURI(), e.getName());
   1.129 +
   1.130 +        if (map.containsKey(name)){
   1.131 +            errReceiver.error(e.getLocator(), WsdlMessages.ENTITY_DUPLICATE_WITH_TYPE(e.getElementName().getLocalPart(), e.getName()));
   1.132 +            throw new AbortException();
   1.133 +        }else{
   1.134 +            map.put(name, e);
   1.135 +        }
   1.136 +    }
   1.137 +
   1.138 +    public GloballyKnown find(Kind k, QName name) {
   1.139 +        Map map = getMap(k);
   1.140 +        Object result = map.get(name);
   1.141 +        if (result == null){
   1.142 +            errReceiver.error(null, WsdlMessages.ENTITY_NOT_FOUND_BY_Q_NAME(k.getName(), name, _systemId));
   1.143 +            throw new AbortException();
   1.144 +        }
   1.145 +        return (GloballyKnown) result;
   1.146 +    }
   1.147 +
   1.148 +    public void validateLocally() {
   1.149 +        LocallyValidatingAction action = new LocallyValidatingAction();
   1.150 +        withAllSubEntitiesDo(action);
   1.151 +        if (action.getException() != null) {
   1.152 +            throw action.getException();
   1.153 +        }
   1.154 +    }
   1.155 +
   1.156 +    public abstract void validate(EntityReferenceValidator validator);
   1.157 +
   1.158 +    protected abstract Entity getRoot();
   1.159 +
   1.160 +    private final Map kinds;
   1.161 +    private String _systemId;
   1.162 +    private final Set importedDocuments;
   1.163 +    private final List importedEntities;
   1.164 +    private final Set includedDocuments;
   1.165 +    private final List includedEntities;
   1.166 +
   1.167 +    private static class LocallyValidatingAction implements EntityAction {
   1.168 +        public LocallyValidatingAction() {
   1.169 +        }
   1.170 +
   1.171 +        @Override
   1.172 +        public void perform(Entity entity) {
   1.173 +            try {
   1.174 +                entity.validateThis();
   1.175 +                entity.withAllSubEntitiesDo(this);
   1.176 +            } catch (ValidationException e) {
   1.177 +                if (_exception == null) {
   1.178 +                    _exception = e;
   1.179 +                }
   1.180 +            }
   1.181 +        }
   1.182 +
   1.183 +        public ValidationException getException() {
   1.184 +            return _exception;
   1.185 +        }
   1.186 +
   1.187 +        private ValidationException _exception;
   1.188 +    }
   1.189 +}

mercurial