KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > extensibility > model > impl > WSDLExtensibilityElementsImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * Created on May 25, 2005
22  *
23  * To change the template for this generated file go to
24  * Window - Preferences - Java - Code Generation - Code and Comments
25  */

26 package org.netbeans.modules.xml.wsdl.ui.extensibility.model.impl;
27
28 import java.io.InputStream JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.logging.Level JavaDoc;
35 import java.util.logging.Logger JavaDoc;
36 import org.netbeans.modules.xml.wsdl.ui.common.Constants;
37
38 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElement;
39 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
40 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.XMLSchemaFileInfo;
41 import org.openide.loaders.DataFolder;
42 import org.openide.loaders.DataObject;
43 import org.openide.util.NbBundle;
44
45
46 /**
47  * @author radval
48  *
49  * To change the template for this generated type comment go to
50  * Window - Preferences - Java - Code Generation - Code and Comments
51  */

52 public class WSDLExtensibilityElementsImpl implements WSDLExtensibilityElements {
53     
54     private static final Logger JavaDoc mLogger = Logger.getLogger(WSDLExtensibilityElementsImpl.class.getName());
55     
56     private DataFolder mRootFolder = null;
57     
58     private Map JavaDoc elementsMap = new HashMap JavaDoc();
59     
60     private Map JavaDoc<String JavaDoc, XMLSchemaFileInfo> schemasMap = new HashMap JavaDoc<String JavaDoc, XMLSchemaFileInfo>();
61     
62     public WSDLExtensibilityElementsImpl(DataFolder rootFolder) {
63         this.mRootFolder = rootFolder;
64         readAllSchemas();
65     }
66     
67     public WSDLExtensibilityElement getWSDLExtensibilityElement(String JavaDoc name) {
68         WSDLExtensibilityElement element = (WSDLExtensibilityElement) elementsMap.get(name);
69         if(element != null) {
70             return element;
71         }
72         
73         DataObject[] dataObjects = this.mRootFolder.getChildren();
74         for(int i = 0; i < dataObjects.length; i++ ) {
75             DataObject dObj = dataObjects[i];
76             if(dObj instanceof DataFolder && dObj.getName().equals(name)) {
77                 element = new WSDLExtensibilityElementImpl((DataFolder) dObj, this);
78                 elementsMap.put(name, element);
79                 break;
80             }
81         }
82         
83         return element;
84     }
85
86     public InputStream JavaDoc[] getAllExtensionSchemas() {
87         ArrayList JavaDoc extensionSchemas = new ArrayList JavaDoc();
88         DataObject[] dataObjects = this.mRootFolder.getChildren();
89         for(int i = 0; i < dataObjects.length; i++ ) {
90             DataObject dObj = dataObjects[i];
91             if(!(dObj instanceof DataFolder) && dObj.getPrimaryFile().hasExt(Constants.XSD_EXT)) {
92                 InputStream JavaDoc in = null;
93                 try {
94                     in = dObj.getPrimaryFile().getInputStream();
95                 } catch(Throwable JavaDoc t) {
96                     mLogger.log(Level.SEVERE, NbBundle.getMessage(WSDLExtensibilityElementsImpl.class, "ERR_MSG_FAILED_TO_GET_SCHEMA", dObj.getPrimaryFile().getPath()));
97                 }
98                 
99                 if(in != null) {
100                     extensionSchemas.add(in);
101                 }
102             }
103         }
104         
105         return (InputStream JavaDoc[]) extensionSchemas.toArray( new InputStream JavaDoc[] {});
106     }
107     
108     public XMLSchemaFileInfo getXMLSchemaFileInfoMatchingFileName(String JavaDoc fileName) {
109         XMLSchemaFileInfo schemaInfo = this.schemasMap.get(fileName);
110         return schemaInfo;
111     }
112     
113     public XMLSchemaFileInfo getXMLSchemaFileInfo(String JavaDoc namespace) {
114         XMLSchemaFileInfo schemaInfo = null;
115
116         Iterator JavaDoc<XMLSchemaFileInfo> it = this.schemasMap.values().iterator();
117         while(it.hasNext()) {
118             XMLSchemaFileInfo info = it.next();
119             String JavaDoc ns = info.getSchema().getTargetNamespace();
120             //String ns = info.getNamespace();
121
if(ns != null && ns.equals(namespace)) {
122                 schemaInfo = info;
123                 break;
124             }
125         }
126
127         return schemaInfo;
128     }
129         
130     private void readAllSchemas() {
131         DataObject[] dataObjects = this.mRootFolder.getChildren();
132         for(int i = 0; i < dataObjects.length; i++ ) {
133             DataObject dObj = dataObjects[i];
134             if(!(dObj instanceof DataFolder) && dObj.getPrimaryFile().hasExt(Constants.XSD_EXT)) {
135                 XMLSchemaFileInfo schemaFileInfo = new XMLSchemaFileInfoImpl(dObj);
136                 this.schemasMap.put(dObj.getName(), schemaFileInfo);
137             }
138         }
139     }
140
141     public XMLSchemaFileInfo[] getAllXMLSchemaFileInfos() {
142         Collection JavaDoc<XMLSchemaFileInfo> infos = schemasMap.values();
143         return infos.toArray(new XMLSchemaFileInfo[infos.size()]);
144     }
145     
146 }
147
Popular Tags