Author: scabanovich
Date: 2007-07-04 11:11:46 -0400 (Wed, 04 Jul 2007)
New Revision: 2288
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/Change.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/IChangeVisitor.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/ISeamProjectChangeListener.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/SeamProjectChangeEvent.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlFactory.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/core/SeamCoreBuilder.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.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/SeamFactory.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/SeamPropertiesDeclaration.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProperty.java
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/scanner/LoadedDeclarations.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/AnnotatedASTNode.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ResolvedAnnotation.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java
Log:
EXIN-217 Merge for incremental build added. Event model 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-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -13,6 +13,7 @@
import java.util.Set;
import org.eclipse.core.resources.IProjectNature;
+import org.jboss.tools.seam.core.event.ISeamProjectChangeListener;
public interface ISeamProject extends IProjectNature {
@@ -101,4 +102,17 @@
* @param factory
*/
public void removeFactory(ISeamFactory factory);
+
+ /**
+ * Adds listener to the project
+ * @param listener
+ */
+ public void addSeamProjectListener(ISeamProjectChangeListener listener);
+
+ /**
+ * Removes listener from the project
+ * @param listener
+ */
+ public void removeSeamProjectListener(ISeamProjectChangeListener listener);
+
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -198,7 +198,8 @@
throws CoreException {
try {
getProject().accept(RESOURCE_VISITOR);
- } catch (CoreException e) {
+ } catch (CoreException e) {
+ e.printStackTrace();
}
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/Change.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/Change.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/Change.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -0,0 +1,118 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.event;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This object collects changes in target that should be fired to listeners.
+ *
+ * @author Viacheslav Kabanovich
+ */
+public class Change {
+ Object target;
+ String property;
+ Object oldValue;
+ Object newValue;
+ List<Change> children;
+
+ /**
+ *
+ * @param target
+ * @param property - name of property changed or null, if change is adding/removing a
child.
+ * @param oldValue - old value; if null and property = null, then child (newValue) is
added
+ * @param newValue - new value; if null and property = null, then child (oldValue) is
removed
+ */
+ public Change(Object target, String property, Object oldValue, Object newValue) {
+ this.target = target;
+ this.property = property;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ public Object getTarget() {
+ return target;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+
+ public Object getOldValue() {
+ return oldValue;
+ }
+
+ public Object getNewValue() {
+ return newValue;
+ }
+
+ public void addChildren(List<Change> children) {
+ if(this.children == null) {
+ this.children = children;
+ } else if(children != null) {
+ this.children.addAll(children);
+ }
+ }
+
+ /**
+ * Returns true if this object defines no actual change in seam model.
+ * @return
+ */
+ public boolean isEmpty() {
+ return oldValue == null && newValue == null && !isChildrenAffected();
+ }
+
+ /**
+ * Returns true if this change includes sub-changes.
+ * @return
+ */
+ public boolean isChildrenAffected() {
+ return children != null && children.size() > 0;
+ }
+
+ /**
+ * Returns list of all changes
+ * @return
+ */
+ public List<Change> getChildren() {
+ return children;
+ }
+
+ /**
+ * Invokes visitor for this change, and if visit returns true, iterates over
+ * child changes.
+ * @param visitor
+ */
+ public void visit(IChangeVisitor visitor) {
+ if(!visitor.visit(this)) return;
+ if(children != null) {
+ for (Change c: children) {
+ c.visit(visitor);
+ }
+ }
+ }
+
+ /**
+ * Utility method to attach a single change to the list. If list is not provided,
+ * new list is created, otherwise the provided list is returned.
+ * @param changes
+ * @param change
+ * @return
+ */
+ public static List<Change> addChange(List<Change> changes, Change change) {
+ if(change == null || change.isEmpty()) return changes;
+ if(changes == null) changes = new ArrayList<Change>();
+ changes.add(change);
+ return changes;
+ }
+
+}
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/IChangeVisitor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/IChangeVisitor.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/IChangeVisitor.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.event;
+
+/**
+ * This interface allows to process SeamProjectChangeEvent, or specific Change by
+ * invoking method visit(IChangeVisitor) declared on them.
+ *
+ * @author Viacheslav Kabanovich
+ */
+public interface IChangeVisitor {
+
+ /**
+ * Processes a single change. If this method returns true,
+ * it shall be invoked with child changes
+ * @param change
+ * @return
+ */
+ public boolean visit(Change change);
+}
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/ISeamProjectChangeListener.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/ISeamProjectChangeListener.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/ISeamProjectChangeListener.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.event;
+
+/**
+ * Interface of an object listening to seam project modifications.
+ *
+ * @author Viacheslav Kabanovich
+ */
+public interface ISeamProjectChangeListener {
+
+ /**
+ * Called when seam project is changed.
+ * Event contains list of structured detailed changes.
+ * It can be conveniently processed using method
+ * event.visit(IChangeVisitor)
+ * @param event
+ */
+ public void projectChanged(SeamProjectChangeEvent event);
+
+}
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/SeamProjectChangeEvent.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/SeamProjectChangeEvent.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/event/SeamProjectChangeEvent.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.event;
+
+import java.util.ArrayList;
+import java.util.EventObject;
+import java.util.List;
+
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamProject;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamProjectChangeEvent extends EventObject {
+ private static final long serialVersionUID = 1L;
+ /**
+ * Modified seam project.
+ */
+ ISeamProject project;
+
+ /**
+ * List of structured changes.
+ */
+ List<Change> changes;
+
+ public SeamProjectChangeEvent(ISeamProject project, List<Change> changes) {
+ super(project);
+ this.changes = changes;
+ }
+
+ /**
+ * Returns modified seam project
+ * @return
+ */
+ public ISeamProject getProject() {
+ return project;
+ }
+
+ /**
+ * Returns all changes
+ * @return
+ */
+ public List<Change> getAllChanges() {
+ return changes;
+ }
+
+ /**
+ * Invokes visitor for each change, which result in iteration over
+ * tree of changes when
+ * @param visitor
+ */
+ public void visit(IChangeVisitor visitor) {
+ if(changes != null) for (Change c: changes) {
+ c.visit(visitor);
+ }
+ }
+
+ /**
+ * Utility method, returns all components that have been modified.
+ * The list does not include removed and added components.
+ * This method makes an example of using visitors to process
+ * seam project events.
+ *
+ * @return
+ */
+ public List<ISeamComponent> getAllModifiedComponents() {
+ final List<ISeamComponent> list = new ArrayList<ISeamComponent>();
+ visit(new IChangeVisitor() {
+ public boolean visit(Change change) {
+ Object t = change.getTarget();
+ if(t instanceof ISeamComponent) {
+ list.add((ISeamComponent)t);
+ } else if(t instanceof ISeamProject) {
+ return true;
+ }
+ return false;
+ }
+ });
+ return list;
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -200,10 +200,22 @@
if(declaration instanceof ISeamJavaComponentDeclaration) {
javaDeclarations.add((ISeamJavaComponentDeclaration)declaration);
} else if(declaration instanceof ISeamXmlComponentDeclaration) {
- xmlDeclarations.add((ISeamXmlComponentDeclaration)xmlDeclarations);
+ xmlDeclarations.add((ISeamXmlComponentDeclaration)declaration);
} else if(declaration instanceof ISeamPropertiesDeclaration) {
propertyDeclarations.add((ISeamPropertiesDeclaration)declaration);
}
}
+
+ public void removeDeclaration(ISeamComponentDeclaration declaration) {
+ if(!allDeclarations.contains(declaration)) return;
+ allDeclarations.remove(declaration);
+ if(declaration instanceof ISeamJavaComponentDeclaration) {
+ javaDeclarations.remove(declaration);
+ } else if(declaration instanceof ISeamXmlComponentDeclaration) {
+ xmlDeclarations.remove(declaration);
+ } else if(declaration instanceof ISeamPropertiesDeclaration) {
+ propertyDeclarations.remove(declaration);
+ }
+ }
}
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-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,9 +1,26 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.seam.internal.core;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.event.Change;
+/**
+ * @author Viacheslav Kabanovich
+ */
public abstract class SeamComponentDeclaration implements ISeamComponentDeclaration {
/**
* Path of resource where this component is declared.
@@ -58,5 +75,29 @@
// TODO Auto-generated method stub
return 0;
}
-
+
+ /**
+ * Merges loaded data into currently used declaration.
+ * If changes were done returns a list of changes.
+ * @param d
+ * @return list of changes
+ */
+ public List<Change> merge(SeamComponentDeclaration d) {
+ List<Change> changes = null;
+ if(!source.equals(d.source)) {
+ source = d.source;
+ }
+ if(!stringsEqual(name, d.name)) {
+ changes = Change.addChange(changes, new Change(this, "name", name,
d.name));
+ name = d.name;
+ }
+ if(id != d.id) id = d.id;
+
+ return changes;
+ }
+
+ boolean stringsEqual(String s1, String s2) {
+ return s1 == null ? s2 == null : s1.equals(s2);
+ }
+
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamFactory.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamFactory.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamFactory.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,8 +1,12 @@
package org.jboss.tools.seam.internal.core;
+import java.util.List;
+
import org.eclipse.core.runtime.IPath;
import org.jboss.tools.seam.core.ISeamFactory;
+import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
import org.jboss.tools.seam.core.ScopeType;
+import org.jboss.tools.seam.core.event.Change;
public class SeamFactory implements ISeamFactory {
/**
@@ -60,4 +64,33 @@
}
}
+ /**
+ * Merges loaded data into currently used declaration.
+ * If changes were done returns a list of changes.
+ * @param f
+ * @return list of changes
+ */
+ public List<Change> merge(SeamFactory f) {
+ List<Change> changes = null;
+
+ source = f.source;
+ id = f.id;
+
+ if(!stringsEqual(name, f.name)) {
+ changes = Change.addChange(changes, new Change(this,
ISeamXmlComponentDeclaration.NAME, name, f.name));
+ name = f.name;
+ }
+ if(!stringsEqual(scope, f.scope)) {
+ changes = Change.addChange(changes, new Change(this,
ISeamXmlComponentDeclaration.SCOPE, scope, f.scope));
+ scope = f.scope;
+ scopeType = f.scopeType;
+ }
+
+ return changes;
+ }
+
+ boolean stringsEqual(String s1, String s2) {
+ return s1 == null ? s2 == null : s1.equals(s2);
+ }
+
}
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-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,9 +1,9 @@
package org.jboss.tools.seam.internal.core;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
-import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.seam.core.BijectedAttributeType;
@@ -13,6 +13,7 @@
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamComponentMethodType;
+import org.jboss.tools.seam.core.event.Change;
public class SeamJavaComponentDeclaration extends SeamComponentDeclaration
implements ISeamJavaComponentDeclaration {
@@ -139,4 +140,42 @@
return type;
}
+ /**
+ * Merges loaded data into currently used declaration.
+ * If changes were done returns a list of changes.
+ * @param d
+ * @return list of changes
+ */
+ public List<Change> merge(SeamComponentDeclaration d) {
+ List<Change> changes = super.merge(d);
+ SeamJavaComponentDeclaration jd = (SeamJavaComponentDeclaration)d;
+ if(!stringsEqual(className, jd.className)) {
+ changes = Change.addChange(changes, new Change(this, "class", className,
jd.className));
+ className = jd.className;
+ }
+ if(scopeType != jd.scopeType) {
+ changes = Change.addChange(changes, new Change(this, "scope", scopeType,
jd.scopeType));
+ scopeType = jd.scopeType;
+ }
+ if(type != jd.type) type = jd.type;
+ if(stateful != jd.stateful) {
+ changes = Change.addChange(changes, new Change(this, "stateful", stateful,
jd.stateful));
+ stateful = jd.stateful;
+ }
+ if(entity != jd.entity) {
+ changes = Change.addChange(changes, new Change(this, "entity", entity,
jd.entity));
+ entity = jd.entity;
+ }
+ Change children = new Change(this, null, null, null);
+
+ //TODO do real merge and add changes to children
+ this.bijectedAttributes = jd.bijectedAttributes;
+ this.componentMethods = jd.componentMethods;
+ this.roles = jd.roles;
+
+ changes = Change.addChange(changes, children);
+
+ return changes;
+ }
+
}
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-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -10,9 +10,11 @@
******************************************************************************/
package org.jboss.tools.seam.internal.core;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -27,18 +29,22 @@
import org.jboss.tools.seam.core.ISeamContextVariable;
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.core.event.ISeamProjectChangeListener;
+import org.jboss.tools.seam.core.event.SeamProjectChangeEvent;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
/**
- * @author glory
+ * @author Viacheslav Kabanovich
*/
public class SeamProject implements ISeamProject {
IProject project;
Map<String, SeamComponent> allComponents = new HashMap<String,
SeamComponent>();
protected Set<ISeamFactory> allFactories = new HashSet<ISeamFactory>();
Set<ISeamContextVariable> allVariables = new
HashSet<ISeamContextVariable>();
+ Map<String, SeamJavaComponentDeclaration> javaDeclarations = new
HashMap<String, SeamJavaComponentDeclaration>();
- Map<String, SeamJavaComponentDeclaration> javaDeclarations = new
HashMap<String, SeamJavaComponentDeclaration>();
+ List<ISeamProjectChangeListener> listeners = new
ArrayList<ISeamProjectChangeListener>();
public SeamProject() {}
@@ -87,8 +93,6 @@
* @param source
*/
public void registerComponents(LoadedDeclarations ds, IPath source) {
- //deprecated
- pathRemoved(source);
SeamComponentDeclaration[] components = ds.getComponents().toArray(new
SeamComponentDeclaration[0]);
SeamFactory[] factories = ds.getFactories().toArray(new SeamFactory[0]);
@@ -98,32 +102,76 @@
return;
}
- Map<Object,ISeamComponentDeclaration> currentDeclarations =
findComponentDeclarations(source);
+ Map<Object,ISeamComponentDeclaration> currentComponents =
findComponentDeclarations(source);
for (int i = 0; i < components.length; i++) {
- components[i].setSourcePath(source);
- String name = components[i].getName();
+ SeamComponentDeclaration loaded = (SeamComponentDeclaration)components[i];
+ SeamComponentDeclaration current =
(SeamComponentDeclaration)currentComponents.remove(loaded.getId());
+
+ loaded.setSourcePath(source);
+
+ String name = loaded.getName();
SeamComponent c = getComponent(name);
+
+ if(current != null) {
+ List<Change> changes = current.merge(loaded);
+ if(changes != null && changes.size() > 0) {
+ Change cc = new Change(c, null, null, null);
+ cc.addChildren(changes);
+ List<Change> cchanges = Change.addChange(null, cc);
+ fireChanges(cchanges);
+ //TODO if java, fire to others
+ }
+ continue;
+ }
+
if(c == null) {
c = newComponent(name);
allComponents.put(name, c);
+ allVariables.add(c);
}
c.addDeclaration(components[i]);
- if(components[i] instanceof ISeamJavaComponentDeclaration) {
+ List<Change> changes = Change.addChange(null, new Change(this, null, null, c));
+ fireChanges(changes);
+
+ if(loaded instanceof ISeamJavaComponentDeclaration) {
javaDeclarations.put(c.getClassName(), (SeamJavaComponentDeclaration)components[i]);
Set<ISeamComponent> cs = getComponentsByClass(c.getClassName());
for (ISeamComponent ci: cs) {
if(ci == c) continue;
SeamComponent cii = (SeamComponent)ci;
- cii.addDeclaration(components[i]);
+ cii.addDeclaration(loaded);
+ changes = Change.addChange(null, new Change(ci, null, null, loaded));
+ fireChanges(changes);
}
- } else if(components[i] instanceof ISeamXmlComponentDeclaration) {
+ } else if(loaded instanceof ISeamXmlComponentDeclaration) {
ISeamXmlComponentDeclaration xml = (ISeamXmlComponentDeclaration)components[i];
String className = xml.getClassName();
SeamJavaComponentDeclaration j = javaDeclarations.get(className);
- if(j != null) c.addDeclaration(j);
+ if(j != null) {
+ c.addDeclaration(j);
+ changes = Change.addChange(null, new Change(c, null, null, j));
+ fireChanges(changes);
+ }
}
}
+
+ componentDeclarationsRemoved(currentComponents);
+
+ Map<Object, ISeamFactory> currentFactories = findFactoryDeclarations(source);
+ for (int i = 0; i < factories.length; i++) {
+ SeamFactory loaded = factories[i];
+ SeamFactory current = (SeamFactory)currentFactories.remove(loaded.getId());
+ if(current != null) {
+ List<Change> changes = current.merge(loaded);
+ fireChanges(changes);
+ continue;
+
+ }
+ }
+
+ factoryDeclarationsRemoved(currentFactories);
+
}
/**
@@ -142,16 +190,38 @@
public void pathRemoved(IPath source) {
Iterator<SeamComponent> iterator = allComponents.values().iterator();
while(iterator.hasNext()) {
- ISeamComponent c = iterator.next();
- Iterator<ISeamComponentDeclaration> ds = c.getAllDeclarations().iterator();
- while (ds.hasNext()) {
- SeamComponentDeclaration di = (SeamComponentDeclaration)ds.next();
- if(di.source.equals(source)) ds.remove();
+ List<Change> changes = null;
+ SeamComponent c = iterator.next();
+ SeamComponentDeclaration[] ds = c.getAllDeclarations().toArray(new
SeamComponentDeclaration[0]);
+ for (int i = 0; i < ds.length; i++) {
+ if(ds[i].source.equals(source)) {
+ c.removeDeclaration(ds[i]);
+ if(ds[i] instanceof ISeamJavaComponentDeclaration) {
+ String className = ((ISeamJavaComponentDeclaration)ds[i]).getClassName();
+ javaDeclarations.remove(className);
+ }
+ changes = Change.addChange(changes, new Change(c, null, ds[i], null));
+ }
}
if(c.getAllDeclarations().size() == 0) {
iterator.remove();
+ allVariables.remove(c);
+ changes = null;
+ changes = Change.addChange(changes, new Change(this, null, c, null));
+
}
- }
+ fireChanges(changes);
+ }
+ Iterator<ISeamFactory> factories = allFactories.iterator();
+ while(factories.hasNext()) {
+ SeamFactory f = (SeamFactory)factories.next();
+ if(source.equals(f.getSourcePath())) {
+ List<Change> changes = Change.addChange(null, new Change(this, null, f,
null));
+ factories.remove();
+ allVariables.remove(f);
+ fireChanges(changes);
+ }
+ }
}
public Map<Object,ISeamComponentDeclaration> findComponentDeclarations(IPath
source) {
@@ -164,7 +234,55 @@
}
return map;
}
+
+ void componentDeclarationsRemoved(Map<Object,ISeamComponentDeclaration> removed)
{
+ Iterator<SeamComponent> iterator = allComponents.values().iterator();
+ while(iterator.hasNext()) {
+ List<Change> changes = null;
+ SeamComponent c = iterator.next();
+ SeamComponentDeclaration[] ds = c.getAllDeclarations().toArray(new
SeamComponentDeclaration[0]);
+ for (int i = 0; i < ds.length; i++) {
+ if(removed.containsKey(ds[i].getId())) {
+ if(ds[i] instanceof ISeamJavaComponentDeclaration) {
+ String className = ((ISeamJavaComponentDeclaration)ds[i]).getClassName();
+ javaDeclarations.remove(className);
+ }
+ c.removeDeclaration(ds[i]);
+ changes = Change.addChange(changes, new Change(c, null, ds[i], null));
+ }
+ }
+ if(c.getAllDeclarations().size() == 0) {
+ iterator.remove();
+ allVariables.remove(c);
+ changes = Change.addChange(null, new Change(this, null, c, null));
+ }
+ fireChanges(changes);
+ }
+ }
+ public Map<Object,ISeamFactory> findFactoryDeclarations(IPath source) {
+ Map<Object,ISeamFactory> map = new HashMap<Object, ISeamFactory>();
+ for (ISeamFactory c: allFactories) {
+ SeamFactory ci = (SeamFactory)c;
+ if(source.equals(ci.getSourcePath())) map.put(ci.getId(), ci);
+ }
+ return map;
+ }
+
+ void factoryDeclarationsRemoved(Map<Object,ISeamFactory> removed) {
+ Iterator<ISeamFactory> iterator = allFactories.iterator();
+ List<Change> changes = null;
+ while(iterator.hasNext()) {
+ SeamFactory c = (SeamFactory)iterator.next();
+ if(removed.containsKey(c.getId())) {
+ iterator.remove();
+ allVariables.remove(c);
+ changes = Change.addChange(changes, new Change(this, null, c, null));
+ }
+ }
+ fireChanges(changes);
+ }
+
//deprecated
public Set<ISeamComponent> getComponentsByName(String name) {
Set<ISeamComponent> result = new HashSet<ISeamComponent>();
@@ -280,6 +398,7 @@
public void removeFactory(ISeamFactory factory) {
allFactories.remove(factory);
+ allVariables.remove(factory);
}
SeamComponent getComponent(String name) {
@@ -291,5 +410,28 @@
c.setName(name);
return c;
}
+
+ void fireChanges(List<Change> changes) {
+ if(changes == null || changes.size() == 0) return;
+ SeamProjectChangeEvent event = new SeamProjectChangeEvent(this, changes);
+ ISeamProjectChangeListener[] ls = null;
+ synchronized(this) {
+ ls = listeners.toArray(new ISeamProjectChangeListener[0]);
+ }
+ if(ls != null) {
+ for (int i = 0; i < ls.length; i++) {
+ ls[i].projectChanged(event);
+ }
+ }
+ }
+ public synchronized void addSeamProjectListener(ISeamProjectChangeListener listener) {
+ if(listeners.contains(listener)) return;
+ listeners.add(listener);
+ }
+
+ public synchronized void removeSeamProjectListener(ISeamProjectChangeListener listener)
{
+ listeners.remove(listener);
+ }
+
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamPropertiesDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamPropertiesDeclaration.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamPropertiesDeclaration.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -6,9 +6,9 @@
import java.util.List;
import java.util.Map;
-import org.eclipse.core.resources.IResource;
import org.jboss.tools.seam.core.ISeamPropertiesDeclaration;
import org.jboss.tools.seam.core.ISeamProperty;
+import org.jboss.tools.seam.core.event.Change;
public class SeamPropertiesDeclaration extends SeamComponentDeclaration
implements ISeamPropertiesDeclaration {
@@ -38,9 +38,50 @@
properties.remove(property.getName());
}
- public void addStringProperty(String name, String value) {
+ public SeamProperty addStringProperty(String name, String value) {
SeamProperty p = new SeamProperty(name, value);
addProperty(p);
+ return p;
}
+ /**
+ * Merges loaded data into currently used declaration.
+ * If changes were done returns a list of changes.
+ * @param d
+ * @return list of changes
+ */
+ public List<Change> merge(SeamComponentDeclaration d) {
+ List<Change> changes = super.merge(d);
+ SeamPropertiesDeclaration pd = (SeamPropertiesDeclaration)d;
+
+ Change children = new Change(this, null, null, null);
+
+ String[] names = properties.keySet().toArray(new String[0]);
+ for (int i = 0; i < names.length; i++) {
+ SeamProperty p1 = (SeamProperty)properties.get(names[i]);
+ SeamProperty p2 = (SeamProperty)pd.properties.get(names[i]);
+ if(p2 == null) {
+ changes = Change.addChange(changes, new Change(this, null, p1, null));
+ properties.remove(names[i]);
+ } else {
+ List<Change> cc = p1.merge(p2);
+ if(cc != null && cc.size() > 0) children.addChildren(cc);
+ }
+ }
+ names = pd.properties.keySet().toArray(new String[0]);
+ for (int i = 0; i < names.length; i++) {
+ SeamProperty p1 = (SeamProperty)properties.get(names[i]);
+ SeamProperty p2 = (SeamProperty)pd.properties.get(names[i]);
+ if(p1 == null) {
+ changes = Change.addChange(changes, new Change(this, null, null, p2));
+ properties.put(names[i], p2);
+ }
+ }
+ properties = pd.properties;
+
+ changes = Change.addChange(changes, children);
+
+ return changes;
+ }
+
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProperty.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProperty.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProperty.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -10,10 +10,16 @@
******************************************************************************/
package org.jboss.tools.seam.internal.core;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import org.eclipse.core.resources.IResource;
import org.jboss.tools.seam.core.ISeamProperty;
+import org.jboss.tools.seam.core.event.Change;
public class SeamProperty implements ISeamProperty {
+ protected Object id;
protected String name;
protected Object value;
protected int startPosition = -1;
@@ -35,6 +41,14 @@
this.value = value;
}
+ public Object getId() {
+ return id;
+ }
+
+ public void setId(Object id) {
+ this.id = id;
+ }
+
public String getName() {
return name;
}
@@ -70,4 +84,59 @@
// TODO Auto-generated method stub
return null;
}
-}
\ No newline at end of file
+
+ public List<Change> merge(SeamProperty d) {
+ List<Change> changes = null;
+
+ id = d.id;
+ startPosition = d.startPosition;
+ length = d.length;
+
+ if(!stringsEqual(name, d.name)) {
+ changes = Change.addChange(changes, new Change(this, "name", name,
d.name));
+ name = d.name;
+ }
+ if(!valuesEqual(value, d.value)) {
+ changes = Change.addChange(changes, new Change(this, "value", value,
d.value));
+ value = d.value;
+ }
+
+ return changes;
+ }
+
+ boolean stringsEqual(String s1, String s2) {
+ return s1 == null ? s2 == null : s1.equals(s2);
+ }
+
+ boolean valuesEqual(Object v1, Object v2) {
+ if(v1 == null) return v2 == null;
+ if(v2 == null) return v1 == null;
+ if(v1 == v2) return true;
+ if(v1 instanceof List && v2 instanceof List) {
+ List<?> l1 = (List<?>)v1;
+ List<?> l2 = (List<?>)v2;
+ if(l1.size() != l2.size()) return false;
+ for (int i = 0; i < l1.size(); i++) {
+ if(!valuesEqual(l1.get(i), l2.get(i))) return false;
+ }
+ return true;
+ } else if(v1 instanceof Map && v2 instanceof Map) {
+ Map<?,?> m1 = (Map<?,?>)v1;
+ Map<?,?> m2 = (Map<?,?>)v2;
+ if(m1.size() != m2.size()) return false;
+ Iterator<?> it = m1.keySet().iterator();
+ while(it.hasNext()) {
+ Object key = it.next();
+ Object o1 = m1.get(key);
+ Object o2 = m2.get(key);
+ if(o2 == null) return false;
+ if(!valuesEqual(o1, o2)) return false;
+ }
+ return true;
+ }
+ if(v1.equals(v2)) return true;
+
+ return false;
+ }
+
+}
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-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlComponentDeclaration.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,7 +1,10 @@
package org.jboss.tools.seam.internal.core;
+import java.util.List;
+
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
import org.jboss.tools.seam.core.ScopeType;
+import org.jboss.tools.seam.core.event.Change;
public class SeamXmlComponentDeclaration extends SeamPropertiesDeclaration
implements ISeamXmlComponentDeclaration {
@@ -74,4 +77,42 @@
this.scope = scope;
}
+ /**
+ * Merges loaded data into currently used declaration.
+ * If changes were done returns a list of changes.
+ * @param d
+ * @return list of changes
+ */
+ public List<Change> merge(SeamComponentDeclaration d) {
+ List<Change> changes = super.merge(d);
+ SeamXmlComponentDeclaration xd = (SeamXmlComponentDeclaration)d;
+
+ if(!stringsEqual(className, xd.className)) {
+ changes = Change.addChange(changes, new Change(this, CLASS, className,
xd.className));
+ className = xd.className;
+ }
+ if(!stringsEqual(autoCreate, xd.autoCreate)) {
+ changes = Change.addChange(changes, new Change(this, AUTO_CREATE, autoCreate,
xd.autoCreate));
+ autoCreate = xd.autoCreate;
+ }
+ if(!stringsEqual(installed, xd.installed)) {
+ changes = Change.addChange(changes, new Change(this, INSTALLED, installed,
xd.installed));
+ installed = xd.installed;
+ }
+ if(!stringsEqual(jndiName, xd.jndiName)) {
+ changes = Change.addChange(changes, new Change(this, JNDI_NAME, jndiName,
xd.jndiName));
+ jndiName = xd.jndiName;
+ }
+ if(!stringsEqual(precedence, xd.precedence)) {
+ changes = Change.addChange(changes, new Change(this, PRECEDENCE, precedence,
xd.precedence));
+ precedence = xd.precedence;
+ }
+ if(!stringsEqual(scope, xd.scope)) {
+ changes = Change.addChange(changes, new Change(this, SCOPE, scope, xd.scope));
+ scope = xd.scope;
+ }
+
+ return changes;
+ }
+
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlFactory.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlFactory.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamXmlFactory.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.jboss.tools.seam.core.ISeamXmlFactory;
+import org.jboss.tools.seam.core.event.Change;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamXmlFactory extends SeamFactory implements ISeamXmlFactory {
+ String method = null;
+ String value = null;
+
+ public String getMethod() {
+ return method;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public int getLength() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public IResource getResource() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getStartPosition() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public List<Change> merge(SeamFactory f) {
+ List<Change> changes = super.merge(f);
+ SeamXmlFactory xf = (SeamXmlFactory)f;
+
+ if(!stringsEqual(value, xf.value)) {
+ changes = Change.addChange(changes, new Change(this, "value", value,
xf.value));
+ value = xf.value;
+ }
+ if(!stringsEqual(method, xf.method)) {
+ changes = Change.addChange(changes, new Change(this, "method", method,
xf.method));
+ method = xf.method;
+ }
+
+ return changes;
+ }
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/LoadedDeclarations.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/LoadedDeclarations.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/LoadedDeclarations.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.seam.internal.core.scanner;
import java.util.ArrayList;
@@ -6,6 +16,11 @@
import org.jboss.tools.seam.internal.core.SeamComponentDeclaration;
import org.jboss.tools.seam.internal.core.SeamFactory;
+/**
+ * This object keeps all declarations loaded from one source.
+ *
+ * @author Viacheslav Kabanovich
+ */
public class LoadedDeclarations {
List<SeamComponentDeclaration> components = new
ArrayList<SeamComponentDeclaration>();
List<SeamFactory> factories = new ArrayList<SeamFactory>();
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,3 +1,13 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.seam.internal.core.scanner.java;
import java.util.HashSet;
@@ -22,6 +32,11 @@
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclaration;
+/**
+ * This object collects changes in target that should be fired to listeners.
+ *
+ * @author Viacheslav Kabanovich
+ */
public class ASTVisitorImpl extends ASTVisitor {
static String SEAM_ANNOTATION_TYPE_PREFIX = "org.jboss.seam.annotations.";
static String NAME_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX + "Name";
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/AnnotatedASTNode.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/AnnotatedASTNode.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/AnnotatedASTNode.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,3 +1,13 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.seam.internal.core.scanner.java;
import org.eclipse.jdt.core.dom.ASTNode;
@@ -2,2 +12,7 @@
+/**
+ * This object binds ASTNode to annotations.
+ *
+ * @author Viacheslav Kabanovich
+ */
public class AnnotatedASTNode {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.seam.internal.core.scanner.java;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -26,11 +25,15 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.util.FileUtil;
-import org.jboss.tools.seam.internal.core.SeamComponentDeclaration;
import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
+/**
+ * This object collects changes in target that should be fired to listeners.
+ *
+ * @author Viacheslav Kabanovich
+ */
public class JavaScanner implements IFileScanner {
public JavaScanner() {}
@@ -72,7 +75,7 @@
public LoadedDeclarations parse(IFile f) throws Exception {
ICompilationUnit u = getCompilationUnit(f);
if(u == null) return null;
- ASTRequestorImpl requestor = new ASTRequestorImpl();
+ ASTRequestorImpl requestor = new ASTRequestorImpl(f.getFullPath());
ICompilationUnit[] us = new ICompilationUnit[]{u};
ASTParser.newParser(AST.JLS3).createASTs(us, new String[0], requestor, null);
return requestor.getDeclarations();
@@ -98,6 +101,11 @@
class ASTRequestorImpl extends ASTRequestor {
private ASTVisitorImpl visitor = new ASTVisitorImpl();
LoadedDeclarations ds = new LoadedDeclarations();
+ IPath sourcePath;
+
+ public ASTRequestorImpl(IPath sourcePath) {
+ this.sourcePath = sourcePath;
+ }
public LoadedDeclarations getDeclarations() {
return ds;
@@ -119,6 +127,10 @@
String n = visitor.type.getElementName();
n = getResolvedType(visitor.type, n);
SeamJavaComponentDeclaration component = new SeamJavaComponentDeclaration();
+
+ component.setId(visitor.type);
+ component.setSourcePath(sourcePath);
+
ds.getComponents().add(component);
component.setType(visitor.type);
component.setId(visitor.type);
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ResolvedAnnotation.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ResolvedAnnotation.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ResolvedAnnotation.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -1,3 +1,13 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.seam.internal.core.scanner.java;
import org.eclipse.jdt.core.dom.Annotation;
@@ -2,2 +12,7 @@
+/**
+ * This object keeps resolved type name for annotation.
+ *
+ * @author Viacheslav Kabanovich
+ */
public class ResolvedAnnotation {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -22,6 +22,9 @@
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
import org.jboss.tools.seam.internal.core.scanner.xml.XMLScanner;
+/**
+ * @author Viacheslav Kabanovich
+ */
public class LibraryScanner implements IFileScanner {
public boolean isRelevant(IFile f) {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java 2007-07-04
14:51:35 UTC (rev 2287)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java 2007-07-04
15:11:46 UTC (rev 2288)
@@ -28,6 +28,7 @@
import org.jboss.tools.seam.internal.core.SeamFactory;
import org.jboss.tools.seam.internal.core.SeamProperty;
import org.jboss.tools.seam.internal.core.SeamXmlComponentDeclaration;
+import org.jboss.tools.seam.internal.core.SeamXmlFactory;
import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
@@ -77,14 +78,13 @@
static Set<String> COMMON_ATTRIBUTES = new HashSet<String>();
static {
- //TODO
-// COMMON_ATTRIBUTES.add(ISeamComponent.NAME);
-// COMMON_ATTRIBUTES.add(ISeamComponent.CLASS);
-// COMMON_ATTRIBUTES.add(ISeamComponent.SCOPE);
-// COMMON_ATTRIBUTES.add(ISeamComponent.PRECEDENCE);
-// COMMON_ATTRIBUTES.add(ISeamComponent.INSTALLED);
-// COMMON_ATTRIBUTES.add(ISeamComponent.AUTO_CREATE);
-// COMMON_ATTRIBUTES.add(ISeamComponent.JNDI_NAME);
+ COMMON_ATTRIBUTES.add(ISeamXmlComponentDeclaration.NAME);
+ COMMON_ATTRIBUTES.add(ISeamXmlComponentDeclaration.CLASS);
+ COMMON_ATTRIBUTES.add(ISeamXmlComponentDeclaration.SCOPE);
+ COMMON_ATTRIBUTES.add(ISeamXmlComponentDeclaration.PRECEDENCE);
+ COMMON_ATTRIBUTES.add(ISeamXmlComponentDeclaration.INSTALLED);
+ COMMON_ATTRIBUTES.add(ISeamXmlComponentDeclaration.AUTO_CREATE);
+ COMMON_ATTRIBUTES.add(ISeamXmlComponentDeclaration.JNDI_NAME);
}
public LoadedDeclarations parse(XModelObject o, IPath source) {
@@ -95,7 +95,10 @@
XModelEntity componentEntity = os[i].getModelEntity();
if(componentEntity.getAttribute("class") != null) {
SeamXmlComponentDeclaration component = new SeamXmlComponentDeclaration();
- //TODO
+
+ component.setSourcePath(source);
+ component.setId(os[i]);
+
component.setName(os[i].getAttributeValue(ISeamXmlComponentDeclaration.NAME));
component.setClassName(os[i].getAttributeValue(ISeamXmlComponentDeclaration.CLASS));
component.setScope(os[i].getAttributeValue(ISeamXmlComponentDeclaration.SCOPE));
@@ -148,17 +151,15 @@
ds.getComponents().add(component);
} else if(os[i].getModelEntity().getName().startsWith("SeamFactory")) {
- //TODO replace with xml factory
- SeamFactory factory = new SeamFactory();
+ SeamXmlFactory factory = new SeamXmlFactory();
factory.setId(os[i]);
factory.setSourcePath(source);
factory.setName(os[i].getAttributeValue(ISeamXmlComponentDeclaration.NAME));
factory.setScopeAsString(os[i].getAttributeValue(ISeamXmlComponentDeclaration.SCOPE));
- String value = os[i].getAttributeValue("value");
- if(factory instanceof ISeamXmlFactory) {
- ((ISeamXmlFactory)factory).setValue(value);
- }
+ factory.setValue(os[i].getAttributeValue("value"));
+ factory.setMethod(os[i].getAttributeValue("method"));
ds.getFactories().add(factory);
+ //TODO assign positioning attributes to created ISeamProperty object
}
}
return ds;