Author: scabanovich
Date: 2007-07-11 10:04:27 -0400 (Wed, 11 Jul 2007)
New Revision: 2385
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamScope.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlComponentDeclaration.java
Log:
EXIN-217 ISeamScope added
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-11
13:16:45 UTC (rev 2384)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-11
14:04:27 UTC (rev 2385)
@@ -21,6 +21,19 @@
public static String NATURE_ID = "org.jboss.tools.seam.core.seam";
/**
+ * Returns list of scope objects for all scope types.
+ * @return
+ */
+ public ISeamScope[] getScopes();
+
+ /**
+ * Returns scope object for specified scope type.
+ * @param scopeType
+ * @return
+ */
+ public ISeamScope getScope(ScopeType scopeType);
+
+ /**
* Returns seam component. Project can have only one ISeamComponent with
* unique name. If project has a few seam components with the same name,
* then corresponding ISeamComponent will have all declarations
@@ -125,5 +138,5 @@
* @param listener
*/
public void removeSeamProjectListener(ISeamProjectChangeListener listener);
-
+
}
\ No newline at end of file
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamScope.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamScope.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamScope.java 2007-07-11
14:04:27 UTC (rev 2385)
@@ -0,0 +1,11 @@
+package org.jboss.tools.seam.core;
+
+import java.util.List;
+
+public interface ISeamScope extends ISeamElement {
+
+ public ScopeType getType();
+
+ public List<ISeamComponent> getComponents();
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java 2007-07-11
13:16:45 UTC (rev 2384)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java 2007-07-11
14:04:27 UTC (rev 2385)
@@ -19,6 +19,7 @@
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
import org.jboss.tools.seam.core.ISeamTextSourceReference;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
+import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.event.Change;
import org.jboss.tools.seam.internal.core.scanner.java.ValueInfo;
@@ -58,6 +59,10 @@
return 0;
}
+ public ScopeType getScope() {
+ return ScopeType.UNSPECIFIED;
+ }
+
/**
* Merges loaded data into currently used declaration.
* If changes were done returns a list of changes.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2007-07-11
13:16:45 UTC (rev 2384)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2007-07-11
14:04:27 UTC (rev 2385)
@@ -48,7 +48,11 @@
if(scope == null || scope.length() == 0) {
scopeType = ScopeType.UNSPECIFIED;
} else {
- scopeType = ScopeType.valueOf(scope.toUpperCase());
+ try {
+ scopeType = ScopeType.valueOf(scope.toUpperCase());
+ } catch (Exception e) {
+ scopeType = ScopeType.UNSPECIFIED;
+ }
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-11
13:16:45 UTC (rev 2384)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-11
14:04:27 UTC (rev 2385)
@@ -31,9 +31,11 @@
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamElement;
import org.jboss.tools.seam.core.ISeamFactory;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.ISeamScope;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamCorePlugin;
@@ -54,6 +56,17 @@
Set<IPath> sourcePaths = new HashSet<IPath>();
private boolean isStorageResolved = false;
+ SeamScope[] scopes = new SeamScope[ScopeType.values().length];
+ Map<ScopeType, SeamScope> scopesMap = new HashMap<ScopeType, SeamScope>();
+
+ {
+ ScopeType[] types = ScopeType.values();
+ for (int i = 0; i < scopes.length; i++) {
+ scopes[i] = new SeamScope(this, types[i]);
+ scopesMap.put(types[i], scopes[i]);
+ }
+ }
+
Map<String, SeamComponent> allComponents = new HashMap<String,
SeamComponent>();
protected Set<ISeamFactory> allFactories = new HashSet<ISeamFactory>();
Set<ISeamContextVariable> allVariables = new
HashSet<ISeamContextVariable>();
@@ -75,6 +88,23 @@
return project;
}
+ /**
+ * Returns list of scope objects for all scope types.
+ * @return
+ */
+ public ISeamScope[] getScopes() {
+ return scopes;
+ }
+
+ /**
+ * Returns scope object for specified scope type.
+ * @param scopeType
+ * @return
+ */
+ public ISeamScope getScope(ScopeType scopeType) {
+ return scopesMap.get(scopeType);
+ }
+
public ISeamProject getSeamProject() {
return this;
}
@@ -82,6 +112,7 @@
public void setProject(IProject project) {
this.project = project;
setSourcePath(project.getFullPath());
+ resource = project;
classPath.init();
load();
}
@@ -106,6 +137,9 @@
public void load() {
if(isStorageResolved) return;
isStorageResolved = true;
+
+ long begin = System.currentTimeMillis();
+
if(getClassPath().update()) {
getClassPath().process();
}
@@ -121,6 +155,10 @@
SeamResourceVisitor b = new SeamResourceVisitor(this);
b.visit(f);
}
+
+ long e = System.currentTimeMillis();
+
+ System.out.println("loaded in " + (e - begin));
}
/**
@@ -166,7 +204,7 @@
* @param source
*/
public void registerComponents(LoadedDeclarations ds, IPath source) {
-
+
SeamComponentDeclaration[] components = ds.getComponents().toArray(new
SeamComponentDeclaration[0]);
ISeamFactory[] factories = ds.getFactories().toArray(new ISeamFactory[0]);
@@ -176,6 +214,8 @@
}
if(!sourcePaths.contains(source)) sourcePaths.add(source);
+ revalidateScopesLock++;
+
Map<Object,ISeamComponentDeclaration> currentComponents =
findComponentDeclarations(source);
List<Change> addedComponents = null;
@@ -214,7 +254,8 @@
}
if(c == null && name != null) {
- c = newComponent(name);
+ ScopeType scopeType = loaded.getScope();
+ c = newComponent(name, scopeType);
allComponents.put(name, c);
allVariables.add(c);
c.addDeclaration(loaded);
@@ -252,7 +293,10 @@
fireChanges(addedComponents);
componentDeclarationsRemoved(currentComponents);
-
+
+ revalidateScopesLock--;
+ revalidateScopes();
+
Map<Object, ISeamFactory> currentFactories = findFactoryDeclarations(source);
List<Change> addedFactories = null;
for (int i = 0; i < factories.length; i++) {
@@ -286,6 +330,7 @@
public void pathRemoved(IPath source) {
if(!sourcePaths.contains(source)) return;
sourcePaths.remove(source);
+ revalidateScopesLock++;
Iterator<SeamComponent> iterator = allComponents.values().iterator();
while(iterator.hasNext()) {
List<Change> changes = null;
@@ -306,6 +351,11 @@
}
if(c.getAllDeclarations().size() == 0) {
iterator.remove();
+ ISeamElement p = c.getParent();
+ if(p instanceof SeamScope) {
+ ((SeamScope)p).removeComponent(c);
+ changes = Change.addChange(changes, new Change(p, null, c, null));
+ }
allVariables.remove(c);
changes = null;
changes = Change.addChange(changes, new Change(this, null, c, null));
@@ -313,6 +363,9 @@
}
fireChanges(changes);
}
+ revalidateScopesLock--;
+ revalidateScopes();
+
Iterator<ISeamFactory> factories = allFactories.iterator();
while(factories.hasNext()) {
AbstractContextVariable f = (AbstractContextVariable)factories.next();
@@ -363,6 +416,11 @@
}
if(c.getAllDeclarations().size() == 0) {
iterator.remove();
+ ISeamElement p = c.getParent();
+ if(p instanceof SeamScope) {
+ ((SeamScope)p).removeComponent(c);
+ changes = Change.addChange(changes, new Change(p, null, c, null));
+ }
allVariables.remove(c);
changes = Change.addChange(null, new Change(this, null, c, null));
}
@@ -507,11 +565,12 @@
return name == null ? null : allComponents.get(name);
}
- SeamComponent newComponent(String name) {
+ SeamComponent newComponent(String name, ScopeType scopeType) {
SeamComponent c = new SeamComponent();
c.setName(name);
c.setId(name);
- c.setParent(this);
+ c.setParent(getScope(scopeType));
+ ((SeamScope)getScope(scopeType)).addComponent(c);
return c;
}
@@ -554,6 +613,26 @@
}
return result;
}
+
+ int revalidateScopesLock = 0;
+ void revalidateScopes() {
+ List<Change> changes = null;
+ if(revalidateScopesLock > 0) return;
+ for(SeamComponent c : allComponents.values()) {
+ SeamScope pc = (SeamScope)c.getParent();
+ SeamScope pn = (SeamScope)getScope(c.getScope());
+ if(pc == pn) continue;
+ c.setParent(pn);
+ if(pc != null) {
+ pc.removeComponent(c);
+ changes = Change.addChange(changes, new Change(pc, null, c, null));
+ }
+ pn.addComponent(c);
+ changes = Change.addChange(changes, new Change(pn, null, null, c));
+ }
+ fireChanges(changes);
+ }
+
}
class InnerBuilder {
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java 2007-07-11
14:04:27 UTC (rev 2385)
@@ -0,0 +1,35 @@
+package org.jboss.tools.seam.internal.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamScope;
+import org.jboss.tools.seam.core.ScopeType;
+
+public class SeamScope extends SeamObject implements ISeamScope {
+ private List<ISeamComponent> components = new ArrayList<ISeamComponent>();
+ private ScopeType scopeType = null;
+
+ SeamScope(SeamProject project, ScopeType scopeType) {
+ setParent(project);
+ this.scopeType = scopeType;
+ }
+
+ public List<ISeamComponent> getComponents() {
+ return components;
+ }
+
+ public void addComponent(ISeamComponent component) {
+ components.add(component);
+ }
+
+ public void removeComponent(ISeamComponent component) {
+ components.remove(component);
+ }
+
+ public ScopeType getType() {
+ return scopeType;
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlComponentDeclaration.java 2007-07-11
13:16:45 UTC (rev 2384)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlComponentDeclaration.java 2007-07-11
14:04:27 UTC (rev 2385)
@@ -38,7 +38,11 @@
public ScopeType getScope() {
if(scope == null || scope.length() == 0) return ScopeType.UNSPECIFIED;
- return ScopeType.valueOf(scope);
+ try {
+ return ScopeType.valueOf(scope);
+ } catch (Exception e) {
+ return ScopeType.UNSPECIFIED;
+ }
}
public String getScopeAsString() {