Author: scabanovich
Date: 2007-10-29 11:05:13 -0400 (Mon, 29 Oct 2007)
New Revision: 4557
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/DataModelSelectionAttribute.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/IBijectedAttribute.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/BijectedAttribute.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java
Log:
JBIDE-1193
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/IBijectedAttribute.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/IBijectedAttribute.java 2007-10-29
14:22:54 UTC (rev 4556)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/IBijectedAttribute.java 2007-10-29
15:05:13 UTC (rev 4557)
@@ -35,6 +35,13 @@
*/
public boolean isContextVariable();
+ /**
+ * Returns value of annotation attribute 'value'.
+ * If value is not set but bijection type defaults value to field name, returns it.
+ * @return
+ */
+ public String getValue();
+
public IBijectedAttribute clone() throws CloneNotSupportedException;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/BijectedAttribute.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/BijectedAttribute.java 2007-10-29
14:22:54 UTC (rev 4556)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/BijectedAttribute.java 2007-10-29
15:05:13 UTC (rev 4557)
@@ -14,13 +14,14 @@
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.IBijectedAttribute;
+import org.jboss.tools.seam.core.IValueInfo;
import org.jboss.tools.seam.core.event.Change;
/**
* @author Viacheslav Kabanovich
*/
public class BijectedAttribute extends SeamJavaContextVariable implements
IBijectedAttribute {
- BijectedAttributeType[] types = null;
+ protected BijectedAttributeType[] types = null;
public BijectedAttribute() {
}
@@ -46,6 +47,14 @@
public void setTypes(BijectedAttributeType[] types) {
this.types = types;
}
+
+ public String getValue() {
+ return getName();
+ }
+
+ public void setValue(String value) {}
+
+ public void setValue(IValueInfo value) {}
public List<Change> merge(SeamObject s) {
List<Change> changes = super.merge(s);
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/DataModelSelectionAttribute.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/DataModelSelectionAttribute.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/DataModelSelectionAttribute.java 2007-10-29
15:05:13 UTC (rev 4557)
@@ -0,0 +1,51 @@
+ /*******************************************************************************
+ * 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.List;
+import org.jboss.tools.seam.core.IValueInfo;
+import org.jboss.tools.seam.core.event.Change;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class DataModelSelectionAttribute extends BijectedAttribute {
+ public static String VALUE = "value";
+ String value;
+
+ public DataModelSelectionAttribute() {}
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public void setValue(IValueInfo value) {
+ attributes.put(VALUE, value);
+ this.value = value == null ? null : value.getValue();
+ }
+
+ public List<Change> merge(SeamObject s) {
+ List<Change> changes = super.merge(s);
+ if(s instanceof DataModelSelectionAttribute) {
+ DataModelSelectionAttribute sf = (DataModelSelectionAttribute)s;
+ if(stringsEqual(this.value, sf.value)) {
+ changes = Change.addChange(changes, new Change(this, VALUE, this.value, sf.value));
+ this.types = sf.types;
+ }
+ }
+ return changes;
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java 2007-10-29
14:22:54 UTC (rev 4556)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java 2007-10-29
15:05:13 UTC (rev 4557)
@@ -35,6 +35,7 @@
import org.jboss.tools.seam.core.IValueInfo;
import org.jboss.tools.seam.core.SeamComponentMethodType;
import org.jboss.tools.seam.internal.core.BijectedAttribute;
+import org.jboss.tools.seam.internal.core.DataModelSelectionAttribute;
import org.jboss.tools.seam.internal.core.Role;
import org.jboss.tools.seam.internal.core.SeamAnnotatedFactory;
import org.jboss.tools.seam.internal.core.SeamComponentMethod;
@@ -146,29 +147,22 @@
}
void processBijections() {
+ Map<BijectedAttributeType, Annotation> as = new HashMap<BijectedAttributeType,
Annotation>();
+ List<BijectedAttributeType> types = new
ArrayList<BijectedAttributeType>();
+
for (AnnotatedASTNode<MethodDeclaration> n: annotatedMethods) {
- Map<BijectedAttributeType, Annotation> as = new
HashMap<BijectedAttributeType, Annotation>();
- List<BijectedAttributeType> types = new
ArrayList<BijectedAttributeType>();
- Annotation main = null;
- for (int i = 0; i < BijectedAttributeType.values().length; i++) {
- Annotation a = findAnnotation(n,
BijectedAttributeType.values()[i].getAnnotationType());
- if(a != null) {
- as.put(BijectedAttributeType.values()[i], a);
- if(main == null) main = a;
- types.add(BijectedAttributeType.values()[i]);
- }
- }
+ Annotation main = getBijectedType(n, as, types);
+
if(as.size() == 0) continue;
+ boolean isDataModelSelectionType = !types.get(0).isUsingMemberName();
MethodDeclaration m = n.getNode();
- BijectedAttribute att = new BijectedAttribute();
- component.addBijectedAttribute(att);
-
- att.setTypes(types.toArray(new BijectedAttributeType[0]));
+ BijectedAttribute att = createBijectedAttribute(types);
ValueInfo name = ValueInfo.getValueInfo(main, null);
- if(name == null && types.size() > 0 &&
types.get(0).isUsingMemberName()) {
+ att.setValue(name);
+ if(name == null || isDataModelSelectionType) {
name = new ValueInfo();
name.value = m.getName().getIdentifier();
}
@@ -184,28 +178,18 @@
}
for (AnnotatedASTNode<FieldDeclaration> n: annotatedFields) {
- Map<BijectedAttributeType, Annotation> as = new
HashMap<BijectedAttributeType, Annotation>();
- List<BijectedAttributeType> types = new
ArrayList<BijectedAttributeType>();
- Annotation main = null;
- for (int i = 0; i < BijectedAttributeType.values().length; i++) {
- Annotation a = findAnnotation(n,
BijectedAttributeType.values()[i].getAnnotationType());
- if(a != null) {
- as.put(BijectedAttributeType.values()[i], a);
- if(main == null) main = a;
- types.add(BijectedAttributeType.values()[i]);
- }
- }
+ Annotation main = getBijectedType(n, as, types);
+
if(as.size() == 0) continue;
+ boolean isDataModelSelectionType = !types.get(0).isUsingMemberName();
FieldDeclaration m = n.getNode();
- BijectedAttribute att = new BijectedAttribute();
- component.addBijectedAttribute(att);
-
- att.setTypes(types.toArray(new BijectedAttributeType[0]));
+ BijectedAttribute att = createBijectedAttribute(types);
ValueInfo name = ValueInfo.getValueInfo(main, null);
- if(name == null) {
+ att.setValue(name);
+ if(name == null || isDataModelSelectionType) {
name = new ValueInfo();
name.value = getFieldName(m);
}
@@ -220,6 +204,30 @@
att.setId(f);
}
}
+ private Annotation getBijectedType(AnnotatedASTNode<?> n,
+ Map<BijectedAttributeType, Annotation> as, List<BijectedAttributeType>
types) {
+ as.clear();
+ types.clear();
+ Annotation main = null;
+ for (int i = 0; i < BijectedAttributeType.values().length; i++) {
+ Annotation a = findAnnotation(n,
BijectedAttributeType.values()[i].getAnnotationType());
+ if(a != null) {
+ as.put(BijectedAttributeType.values()[i], a);
+ if(main == null) main = a;
+ types.add(BijectedAttributeType.values()[i]);
+ }
+ }
+ return main;
+ }
+ private BijectedAttribute createBijectedAttribute(List<BijectedAttributeType>
types) {
+ boolean isDataModelSelectionType = !types.get(0).isUsingMemberName();
+ BijectedAttribute att = (!isDataModelSelectionType)
+ ? new BijectedAttribute() : new DataModelSelectionAttribute();
+ component.addBijectedAttribute(att);
+ att.setTypes(types.toArray(new BijectedAttributeType[0]));
+
+ return att;
+ }
void processComponentMethods() {
for (AnnotatedASTNode<MethodDeclaration> n: annotatedMethods) {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java 2007-10-29
14:22:54 UTC (rev 4556)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java 2007-10-29
15:05:13 UTC (rev 4557)
@@ -42,6 +42,7 @@
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.AbstractContextVariable;
import org.jboss.tools.seam.internal.core.BijectedAttribute;
+import org.jboss.tools.seam.internal.core.DataModelSelectionAttribute;
import org.jboss.tools.seam.internal.core.SeamAnnotatedFactory;
import org.jboss.tools.seam.internal.core.SeamComponentMethod;
import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
@@ -240,14 +241,18 @@
}
}
if(as.size() == 0) return;
+
+ boolean isDataModelSelectionType = !types.get(0).isUsingMemberName();
- BijectedAttribute att = new BijectedAttribute();
+ BijectedAttribute att = (!isDataModelSelectionType)
+ ? new BijectedAttribute() : new DataModelSelectionAttribute();
component.addBijectedAttribute(att);
att.setTypes(types.toArray(new BijectedAttributeType[0]));
String name = (String)getValue(main, "value"); //$NON-NLS-1$
- if(name == null || name.length() == 0) {
+ att.setValue(name);
+ if(name == null || name.length() == 0 || isDataModelSelectionType) {
name = new String(m.getSelector());
}
att.setName(name);