Author: scabanovich
Date: 2010-01-15 05:58:21 -0500 (Fri, 15 Jan 2010)
New Revision: 19764
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/StaticLibraries.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5650
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2010-01-15
07:36:59 UTC (rev 19763)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2010-01-15
10:58:21 UTC (rev 19764)
@@ -93,7 +93,11 @@
* @see org.jboss.tools.jst.web.kb.IKbProject#getTagLibraries(java.lang.String)
*/
public ITagLibrary[] getTagLibraries(String uri) {
- return libraries.getLibrariesArray(uri);
+ ITagLibrary[] result = libraries.getLibrariesArray(uri);
+ if(result == null || result.length == 0) {
+ result = StaticLibraries.instance.getLibraries(uri);
+ }
+ return result;
}
/*
@@ -749,130 +753,6 @@
//TODO Implement if it will be needed events and listeners. and fire events to them.
}
- class LibraryStorage {
- private Set<ITagLibrary> allLibraries = new HashSet<ITagLibrary>();
- private ITagLibrary[] allLibrariesArray = null;
- Map<IPath, Set<ITagLibrary>> librariesBySource = new HashMap<IPath,
Set<ITagLibrary>>();
- Map<String, Set<ITagLibrary>> librariesByUri = new HashMap<String,
Set<ITagLibrary>>();
- private Map<String,ITagLibrary[]> librariesByUriArray = new HashMap<String,
ITagLibrary[]>();
-
- public void clear() {
- synchronized(allLibraries) {
- allLibraries.clear();
- allLibrariesArray = null;
- }
- librariesBySource.clear();
- synchronized (librariesByUri) {
- librariesByUri.clear();
- librariesByUriArray.clear();
- }
- }
-
- public ITagLibrary[] getAllLibrariesArray() {
- if(allLibrariesArray == null) {
- synchronized(allLibraries) {
- allLibrariesArray = allLibraries.toArray(new ITagLibrary[0]);
- }
- }
- return allLibrariesArray;
- }
-
- public ITagLibrary[] getLibrariesArray(String uri) {
- ITagLibrary[] result = librariesByUriArray.get(uri);
- if(result == null) {
- synchronized(librariesByUri) {
- Set<ITagLibrary> libs = librariesByUri.get(uri);
- if(libs!=null) {
- result = libs.toArray(new ITagLibrary[0]);
- } else {
- result = new ITagLibrary[0];
- }
- librariesByUriArray.put(uri, result);
- }
- }
- return result;
- }
-
- public Set<ITagLibrary> getLibrariesBySource(IPath path) {
- return librariesBySource.get(path);
- }
-
- public void addLibrary(ITagLibrary f) {
- synchronized(allLibraries) {
- allLibraries.add(f);
- allLibrariesArray = null;
- }
- IPath path = f.getSourcePath();
- if(path != null) {
- Set<ITagLibrary> fs = librariesBySource.get(path);
- if(fs == null) {
- fs = new HashSet<ITagLibrary>();
- librariesBySource.put(path, fs);
- }
- fs.add(f);
- }
- String uri = f.getURI();
- synchronized (librariesByUri) {
- librariesByUriArray.remove(uri);
- Set<ITagLibrary> ul = librariesByUri.get(uri);
- if (ul == null) {
- ul = new HashSet<ITagLibrary>();
- librariesByUri.put(uri, ul);
- }
- ul.add(f);
- }
- }
-
- public void removeLibrary(ITagLibrary f) {
- synchronized(allLibraries) {
- allLibraries.remove(f);
- allLibrariesArray = null;
- }
- IPath path = f.getSourcePath();
- if(path != null) {
- Set<ITagLibrary> fs = librariesBySource.get(path);
- if(fs != null) {
- fs.remove(f);
- }
- if(fs.isEmpty()) {
- librariesBySource.remove(fs);
- }
- }
- String uri = f.getURI();
- synchronized (librariesByUri) {
- Set<ITagLibrary> ul = librariesByUri.get(uri);
- librariesByUriArray.remove(uri);
- if (ul != null) {
- ul.remove(f);
- if (ul.isEmpty()) {
- librariesByUri.remove(uri);
- }
- }
- }
- }
-
- public Set<ITagLibrary> removePath(IPath path) {
- Set<ITagLibrary> fs = librariesBySource.get(path);
- if(fs == null) return null;
- for (ITagLibrary f: fs) {
- synchronized(allLibraries) {
- allLibraries.remove(f);
- allLibrariesArray = null;
- }
- synchronized (librariesByUri) {
- Set<ITagLibrary> s = librariesByUri.get(f.getURI());
- if(s != null) s.remove(f);
- if(s != null && s.isEmpty()) {
- librariesByUri.remove(f.getURI());
- }
- librariesByUriArray.remove(f.getURI());
- }
- }
- librariesBySource.remove(path);
- return fs;
- }
- }
-
/**
* Check if KB builder is installed and add a warning with quick fix to the project if
it is not.
* @param resource
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java 2010-01-15
10:58:21 UTC (rev 19764)
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.internal;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class LibraryStorage {
+ private Set<ITagLibrary> allLibraries = new HashSet<ITagLibrary>();
+ private ITagLibrary[] allLibrariesArray = null;
+ Map<IPath, Set<ITagLibrary>> librariesBySource = new HashMap<IPath,
Set<ITagLibrary>>();
+ Map<String, Set<ITagLibrary>> librariesByUri = new HashMap<String,
Set<ITagLibrary>>();
+ private Map<String,ITagLibrary[]> librariesByUriArray = new HashMap<String,
ITagLibrary[]>();
+
+ public void clear() {
+ synchronized(allLibraries) {
+ allLibraries.clear();
+ allLibrariesArray = null;
+ }
+ librariesBySource.clear();
+ synchronized (librariesByUri) {
+ librariesByUri.clear();
+ librariesByUriArray.clear();
+ }
+ }
+
+ public ITagLibrary[] getAllLibrariesArray() {
+ if(allLibrariesArray == null) {
+ synchronized(allLibraries) {
+ allLibrariesArray = allLibraries.toArray(new ITagLibrary[0]);
+ }
+ }
+ return allLibrariesArray;
+ }
+
+ public ITagLibrary[] getLibrariesArray(String uri) {
+ ITagLibrary[] result = librariesByUriArray.get(uri);
+ if(result == null) {
+ synchronized(librariesByUri) {
+ Set<ITagLibrary> libs = librariesByUri.get(uri);
+ if(libs!=null) {
+ result = libs.toArray(new ITagLibrary[0]);
+ } else {
+ result = new ITagLibrary[0];
+ }
+ librariesByUriArray.put(uri, result);
+ }
+ }
+ return result;
+ }
+
+ public Set<ITagLibrary> getLibrariesBySource(IPath path) {
+ return librariesBySource.get(path);
+ }
+
+ public void addLibrary(ITagLibrary f) {
+ synchronized(allLibraries) {
+ allLibraries.add(f);
+ allLibrariesArray = null;
+ }
+ IPath path = f.getSourcePath();
+ if(path != null) {
+ Set<ITagLibrary> fs = librariesBySource.get(path);
+ if(fs == null) {
+ fs = new HashSet<ITagLibrary>();
+ librariesBySource.put(path, fs);
+ }
+ fs.add(f);
+ }
+ String uri = f.getURI();
+ synchronized (librariesByUri) {
+ librariesByUriArray.remove(uri);
+ Set<ITagLibrary> ul = librariesByUri.get(uri);
+ if (ul == null) {
+ ul = new HashSet<ITagLibrary>();
+ librariesByUri.put(uri, ul);
+ }
+ ul.add(f);
+ }
+ }
+
+ public void removeLibrary(ITagLibrary f) {
+ synchronized(allLibraries) {
+ allLibraries.remove(f);
+ allLibrariesArray = null;
+ }
+ IPath path = f.getSourcePath();
+ if(path != null) {
+ Set<ITagLibrary> fs = librariesBySource.get(path);
+ if(fs != null) {
+ fs.remove(f);
+ }
+ if(fs.isEmpty()) {
+ librariesBySource.remove(fs);
+ }
+ }
+ String uri = f.getURI();
+ synchronized (librariesByUri) {
+ Set<ITagLibrary> ul = librariesByUri.get(uri);
+ librariesByUriArray.remove(uri);
+ if (ul != null) {
+ ul.remove(f);
+ if (ul.isEmpty()) {
+ librariesByUri.remove(uri);
+ }
+ }
+ }
+ }
+
+ public Set<ITagLibrary> removePath(IPath path) {
+ Set<ITagLibrary> fs = librariesBySource.get(path);
+ if(fs == null) return null;
+ for (ITagLibrary f: fs) {
+ synchronized(allLibraries) {
+ allLibraries.remove(f);
+ allLibrariesArray = null;
+ }
+ synchronized (librariesByUri) {
+ Set<ITagLibrary> s = librariesByUri.get(f.getURI());
+ if(s != null) s.remove(f);
+ if(s != null && s.isEmpty()) {
+ librariesByUri.remove(f.getURI());
+ }
+ librariesByUriArray.remove(f.getURI());
+ }
+ }
+ librariesBySource.remove(path);
+ return fs;
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/StaticLibraries.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/StaticLibraries.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/StaticLibraries.java 2010-01-15
10:58:21 UTC (rev 19764)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.internal;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jst.web.kb.internal.scanner.LoadedDeclarations;
+import org.jboss.tools.jst.web.kb.internal.scanner.XMLScanner;
+import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
+import org.jboss.tools.jst.web.kb.taglib.TagLibraryManager;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class StaticLibraries {
+ static StaticLibraries instance = new StaticLibraries();
+
+ LibraryStorage libraries = new LibraryStorage();
+ HashMap<File, XModel> loaded = new HashMap<File, XModel>();
+
+ private StaticLibraries() {}
+
+ public ITagLibrary[] getLibraries(String uri) {
+ File file = TagLibraryManager.getStaticTLD(uri);
+ if(file == null) return new ITagLibrary[0];
+ File folder = file.getParentFile();
+ if(!loaded.containsKey(folder)) {
+ XModelObject o = EclipseResourceUtil.createObjectForLocation(file.getAbsolutePath());
+ if(o != null) {
+ loaded.put(folder, o.getModel());
+ XModelObject[] fs = o.getParent().getChildren();
+ XMLScanner scanner = new XMLScanner();
+ for (XModelObject fo: fs) {
+ LoadedDeclarations ds = scanner.parse(fo, new Path(folder.getAbsolutePath()),
null);
+ List<ITagLibrary> ls = ds.getLibraries();
+ for (ITagLibrary l: ls) {
+ libraries.addLibrary(l);
+ }
+ }
+ }
+ }
+ return libraries.getLibrariesArray(uri);
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/StaticLibraries.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain