001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /**
021: *
022: */package org.netbeans.modules.bpel.model.impl.references;
023:
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.LinkedList;
027: import java.util.List;
028:
029: import org.netbeans.modules.bpel.model.api.BpelModel;
030: import org.netbeans.modules.bpel.model.api.Import;
031: import org.netbeans.modules.bpel.model.api.support.ImportHelper;
032: import org.netbeans.modules.bpel.model.impl.Utils;
033: import org.netbeans.modules.bpel.model.xam.spi.ExternalModelRetriever;
034: import org.netbeans.modules.xml.schema.model.SchemaModel;
035: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
036: import org.netbeans.modules.xml.xam.Model;
037: import org.netbeans.modules.xml.xam.Model.State;
038:
039: //import org.openide.filesystems.FileObject;
040:
041: /**
042: * @author ads
043: *
044: */
045: public class ExternalModelRetrieverImpl implements
046: ExternalModelRetriever {
047:
048: /* (non-Javadoc)
049: * @see org.netbeans.modules.bpel.model.xam.spi.ExternalModelRetriever#getWSDLModels(org.netbeans.modules.bpel.model.api.BpelModel, java.lang.String)
050: */
051: @SuppressWarnings("unchecked")
052: public Collection<WSDLModel> getWSDLModels(BpelModel model,
053: String namespace) {
054: if (namespace == null) {
055: return Collections.EMPTY_LIST;
056: }
057: List<WSDLModel> list = new LinkedList<WSDLModel>();
058: collectWsdlModelsViaImports(model, namespace, list);
059:
060: //collectWsdlModelsViaFS(model, namespace, list);
061:
062: return list;
063:
064: }
065:
066: /* (non-Javadoc)
067: * @see org.netbeans.modules.bpel.model.xam.spi.ExternalModelRetriever#getSchemaModels(org.netbeans.modules.bpel.model.api.BpelModel, java.lang.String)
068: */
069: @SuppressWarnings("unchecked")
070: public Collection<SchemaModel> getSchemaModels(BpelModel model,
071: String namespace) {
072: if (namespace == null) {
073: return Collections.EMPTY_LIST;
074: }
075: List<SchemaModel> list = new LinkedList<SchemaModel>();
076:
077: collectShemaModelsViaImports(model, namespace, list);
078: //collectSchemaModelsViaFS(model, namespace, list);
079: return list;
080:
081: }
082:
083: /*private void collectWsdlModelsViaFS( BpelModel model, String namespace,
084: List<WSDLModel> list )
085: {
086: FileObject[] files = Utils.getFilesByNamespace( model.getModelSource() ,
087: namespace , DocumentTypesEnum.wsdl );
088: for (FileObject file : files) {
089: WSDLModel wsdlModel;
090: try {
091: ModelSource modelSource = Utilities.getModelSource( file , true );
092: wsdlModel = WSDLModelFactory.getDefault().
093: getModel( modelSource );
094: }
095: catch (IOException e) {
096: // The model that we trying to access is possibly broken.
097: // SO we skip it in out list.
098: wsdlModel = null;
099: }
100:
101: if ( wsdlModel != null ){
102: list.add( wsdlModel );
103: }
104: }
105: }*/
106:
107: private void collectWsdlModelsViaImports(BpelModel model,
108: String namespace, List<WSDLModel> list) {
109: Import[] imports = model.getProcess().getImports();
110: for (Import imp : imports) {
111: if (namespace.equals(imp.getNamespace())) {
112: WSDLModel wsdlModel = ImportHelper.getWsdlModel(imp);
113: if (wsdlModel != null
114: && wsdlModel.getState() == Model.State.VALID) {
115: list.add(wsdlModel);
116: }
117: }
118: }
119: }
120:
121: /*private void collectSchemaModelsViaFS( BpelModel model, String namespace,
122: List<SchemaModel> list )
123: {
124: FileObject[] files = Utils.getFilesByNamespace( model.getModelSource() ,
125: namespace , DocumentTypesEnum.schema );
126: for (FileObject file : files) {
127: SchemaModel schemaModel ;
128: try {
129: ModelSource modelSource = Utilities.getModelSource( file , true );
130: schemaModel = SchemaModelFactory.getDefault().
131: getModel( modelSource );
132: }
133: catch (IOException e) {
134: // The model that we trying to access is possibly broken.
135: // SO we skip it in out list.
136: schemaModel = null;
137: }
138: if ( schemaModel != null && model.getState() == Model.State.VALID){
139: list.add( schemaModel );
140: }
141: }
142: }*/
143:
144: private void collectShemaModelsViaImports(BpelModel model,
145: String namespace, List<SchemaModel> list) {
146: Import[] imports = model.getProcess().getImports();
147: for (Import imp : imports) {
148: if (Import.WSDL_IMPORT_TYPE.equals(imp.getImportType())) {
149: // Fix for #78085
150: Collection<SchemaModel> collection = ImportHelper
151: .getInlineSchema(imp, namespace);
152: if (collection != null) {
153: list.addAll(collection);
154: }
155: }
156: if (!namespace.equals(imp.getNamespace())) {
157: continue;
158: }
159: SchemaModel schemaModel = ImportHelper.getSchemaModel(imp);
160: if (schemaModel != null
161: && schemaModel.getState() == State.VALID) {
162: list.add(schemaModel);
163: }
164: }
165: }
166:
167: }
|