Author: scabanovich
Date: 2009-05-15 12:31:45 -0400 (Fri, 15 May 2009)
New Revision: 15302
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/ITextSourceReference.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/IValueInfo.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/Change.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/IChangeVisitor.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/impl/
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/impl/ValueInfo.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/store/
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/store/XMLStoreConstants.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
Modified: trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2009-05-15
16:25:48 UTC (rev 15301)
+++ trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2009-05-15
16:31:45 UTC (rev 15302)
@@ -31,6 +31,10 @@
org.jboss.tools.common.model.options.impl,
org.jboss.tools.common.model.plugin,
org.jboss.tools.common.model.project,
+ org.jboss.tools.common.model.project.ext,
+ org.jboss.tools.common.model.project.ext.store,
+ org.jboss.tools.common.model.project.ext.event,
+ org.jboss.tools.common.model.project.ext.impl,
org.jboss.tools.common.model.undo,
org.jboss.tools.common.model.util,
org.jboss.tools.common.model.util.extension,
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/ITextSourceReference.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/ITextSourceReference.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/ITextSourceReference.java 2009-05-15
16:31:45 UTC (rev 15302)
@@ -0,0 +1,28 @@
+ /*******************************************************************************
+ * 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.common.model.project.ext;
+
+/**
+ * An interface of seam tools model object that has text source.
+ * @author Alexey Kazakov
+ */
+public interface ITextSourceReference {
+
+ /**
+ * @return start position of element in text
+ */
+ public int getStartPosition();
+
+ /**
+ * @return number of characters of element in text
+ */
+ public int getLength();
+}
\ No newline at end of file
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/IValueInfo.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/IValueInfo.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/IValueInfo.java 2009-05-15
16:31:45 UTC (rev 15302)
@@ -0,0 +1,31 @@
+ /*******************************************************************************
+ * 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.common.model.project.ext;
+
+import java.util.Properties;
+
+import org.w3c.dom.Element;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public interface IValueInfo extends ITextSourceReference {
+
+ /**
+ * Returns string value
+ * @return
+ */
+ public String getValue();
+
+ public Element toXML(Element parent, Properties context);
+
+ public void loadXML(Element element, Properties context);
+}
\ No newline at end of file
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/Change.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/Change.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/Change.java 2009-05-15
16:31:45 UTC (rev 15302)
@@ -0,0 +1,125 @@
+ /*******************************************************************************
+ * 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.common.model.project.ext.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;
+
+ /**
+ * Constructs object with initial values
+ *
+ * @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.isEmpty();
+ }
+
+ /**
+ * 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/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/IChangeVisitor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/IChangeVisitor.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/event/IChangeVisitor.java 2009-05-15
16:31:45 UTC (rev 15302)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.project.ext.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/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/impl/ValueInfo.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/impl/ValueInfo.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/impl/ValueInfo.java 2009-05-15
16:31:45 UTC (rev 15302)
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.model.project.ext.impl;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.MemberValuePair;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.jboss.tools.common.model.project.ext.IValueInfo;
+import org.jboss.tools.common.model.project.ext.store.XMLStoreConstants;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.w3c.dom.Element;
+
+public class ValueInfo implements IValueInfo {
+ String value;
+ public int valueStartPosition;
+ public int valueLength;
+
+ /**
+ * Factory method.
+ * @param node
+ * @param name
+ * @return
+ */
+ public static ValueInfo getValueInfo(Annotation node, String name) {
+ if(name == null) name = "value"; //$NON-NLS-1$
+ if(node instanceof SingleMemberAnnotation) {
+ if(name == null || "value".equals(name)) { //$NON-NLS-1$
+ SingleMemberAnnotation m = (SingleMemberAnnotation)node;
+ ValueInfo result = new ValueInfo();
+ Expression exp = m.getValue();
+ result.valueLength = exp.getLength();
+ result.valueStartPosition = exp.getStartPosition();
+ result.value = checkExpression(exp);
+ return result;
+ }
+ return null;
+ } else if(node instanceof NormalAnnotation) {
+ NormalAnnotation n = (NormalAnnotation)node;
+ List<?> vs = n.values();
+ if(vs != null) for (int i = 0; i < vs.size(); i++) {
+ MemberValuePair p = (MemberValuePair)vs.get(i);
+ String pname = p.getName().getIdentifier();
+ if(!name.equals(pname)) continue;
+ ValueInfo result = new ValueInfo();
+ Expression exp = p.getValue();
+ result.valueLength = exp.getLength();
+ result.valueStartPosition = exp.getStartPosition();
+ result.value = checkExpression(exp);
+ return result;
+ }
+ return null;
+ }
+ return null;
+ }
+
+ public ValueInfo() {
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public int getStartPosition() {
+ return valueStartPosition;
+ }
+
+ public int getLength() {
+ return valueLength;
+ }
+
+ static String checkExpression(Expression exp) {
+ if(exp == null) return null;
+ if(exp instanceof StringLiteral) {
+ return ((StringLiteral)exp).getLiteralValue();
+ } else if(exp instanceof QualifiedName) {
+ Object o = exp.resolveConstantExpressionValue();
+ if(o != null) return o.toString();
+ return exp.toString();
+ }
+ Object o = exp.resolveConstantExpressionValue();
+ if(o != null) return o.toString();
+ return exp.toString();
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public Element toXML(Element parent, Properties context) {
+ Element element = XMLUtilities.createElement(parent,
XMLStoreConstants.TAG_VALUE_INFO);
+ if(value != null) element.setAttribute(XMLStoreConstants.ATTR_VALUE, value);
+ if(valueStartPosition != 0) element.setAttribute(ATTR_START, "" +
valueStartPosition);
+ if(valueLength != 0) element.setAttribute(ATTR_LENGTH, "" + valueLength);
+ return element;
+ }
+
+ static String ATTR_START = "start";
+ static String ATTR_LENGTH = "length";
+
+ public void loadXML(Element element, Properties context) {
+ value = element.getAttribute(XMLStoreConstants.ATTR_VALUE);
+ String start = element.getAttribute(ATTR_START);
+ if(start != null && start.length() > 0) {
+ try {
+ valueStartPosition = Integer.parseInt(start);
+ } catch (NumberFormatException e) {
+ //ignore
+ }
+ }
+ String length = element.getAttribute(ATTR_LENGTH);
+ if(length != null && length.length() > 0) {
+ try {
+ valueLength = Integer.parseInt(length);
+ } catch (NumberFormatException e) {
+ //ignore
+ }
+ }
+ }
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/store/XMLStoreConstants.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/store/XMLStoreConstants.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/store/XMLStoreConstants.java 2009-05-15
16:31:45 UTC (rev 15302)
@@ -0,0 +1,39 @@
+ /*******************************************************************************
+ * 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.common.model.project.ext.store;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public interface XMLStoreConstants {
+ public String TAG_VALUE_INFO = "value-info";
+ public String TAG_ID = "id";
+ public String TAG_ENTRY = "entry";
+
+ public String CLS_XML = "xml";
+ public String CLS_MODEL_OBJECT = "model-object";
+ public String CLS_FIELD = "field";
+ public String CLS_STRING = "string";
+ public String CLS_TYPE = "type";
+ public String CLS_METHOD = "method";
+
+
+ public String ATTR_VALUE = "value";
+ public String ATTR_PATH = "path";
+ public String ATTR_CLASS = "class";
+ public String ATTR_NAME = "name";
+ public String ATTR_PROJECT = "project";
+ public String ATTR_TYPE = "type";
+ public String ATTR_PARAMS = "params";
+
+ public String KEY_MODEL_OBJECT = "model-object";
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ext/store/XMLStoreConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain