You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by mb...@apache.org on 2007/02/14 15:35:47 UTC
svn commit: r507542 [3/10] - in /incubator/uima/sandbox/trunk/CasEditor: ./
icons/ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/uima/
src/main/java/org/apache/uima/caseditor/ src/main/java/org/apac...
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/AbstractResourceDelta.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/AbstractResourceDelta.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/AbstractResourceDelta.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/AbstractResourceDelta.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.delta;
+
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * Abstract base class, so clients must not implement all methods.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.2.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public abstract class AbstractResourceDelta implements IResourceDelta {
+ /**
+ * Dummy method, does nothing.
+ */
+ public void accept(IResourceDeltaVisitor visitor) throws CoreException {
+ // not implemented
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public void accept(IResourceDeltaVisitor visitor, boolean includePhantoms) throws CoreException {
+ // not implemented
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public void accept(IResourceDeltaVisitor visitor, int memberFlags) throws CoreException {
+ // not implemented
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IResourceDelta findMember(IPath path) {
+ return null;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IResourceDelta[] getAffectedChildren() {
+ return new IResourceDelta[] {};
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IResourceDelta[] getAffectedChildren(int kindMask) {
+ return new IResourceDelta[] {};
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IResourceDelta[] getAffectedChildren(int kindMask, int memberFlags) {
+ return new IResourceDelta[] {};
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public int getFlags() {
+ return 0;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IPath getFullPath() {
+ return null;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public int getKind() {
+ return 0;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IMarkerDelta[] getMarkerDeltas() {
+ return new IMarkerDelta[] {};
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IPath getMovedFromPath() {
+ return null;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IPath getMovedToPath() {
+ return null;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IPath getProjectRelativePath() {
+ return null;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public IResource getResource() {
+ return null;
+ }
+
+ /**
+ * Dummy method, does nothing.
+ */
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpElementDelta.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpElementDelta.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpElementDelta.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpElementDelta.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.delta;
+
+
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * A element delta represents changes in the state of a element tree between two discrete points in
+ * time.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.3.2.2 $, $Date: 2007/01/04 14:56:25 $
+ */
+public interface INlpElementDelta {
+ /**
+ * Accepts the given visitor. The only kinds of resource deltas visited are <code>ADDED</code>,
+ * <code>REMOVED</code>, and <code>CHANGED</code>.
+ *
+ * @param visotor
+ */
+ void accept(INlpModelDeltaVisitor visotor);
+
+ /**
+ * Returns resource deltas for all children of this resource which were added, removed, or
+ * changed. Returns an empty array if there are no affected children.
+ *
+ * @return - childs or empty array
+ */
+ public INlpElementDelta[] getAffectedChildren();
+
+ /**
+ * Returns true if the given element is an nlp element.
+ *
+ * @return true if an nlp element otherwise false
+ */
+ boolean isNlpElement();
+
+ /**
+ * Retrives the nlp element.
+ *
+ * @return the nlp element or if non null.
+ */
+ INlpElement getNlpElement();
+
+ /**
+ * Retrives the resource belonging to this delta.
+ *
+ * @return the resource
+ */
+ IResource getResource();
+
+ /**
+ * Retrives the kind.
+ *
+ * @return the kind
+ */
+ Kind getKind();
+
+ /**
+ * Retrives the flags.
+ *
+ * @return the flags
+ */
+ int getFlags();
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelChangeListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelChangeListener.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelChangeListener.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelChangeListener.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.delta;
+
+import org.apache.uima.caseditor.core.model.INlpElement;
+
+/**
+ * This listener is notfied when the nlp model changes.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.2.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public interface INlpModelChangeListener {
+ /**
+ * Called if the nlp model changed.
+ *
+ * @param delta
+ * contains the change from one point in time to the next.
+ */
+ void resourceChanged(INlpElementDelta delta);
+
+ /**
+ * The given {@link INlpElement} was changed. Clients must refresh.
+ *
+ * @param element
+ */
+ void refresh(INlpElement element);
+}
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelDeltaVisitor.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelDeltaVisitor.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelDeltaVisitor.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/INlpModelDeltaVisitor.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.delta;
+
+/**
+ * The listener is used to visit the given delta.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.2.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public interface INlpModelDeltaVisitor {
+ /**
+ * Called to visit the given delta.
+ *
+ * @param delta
+ * @return true if the implemntor wants to visit childs.
+ */
+ public boolean visit(INlpElementDelta delta);
+}
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/Kind.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/Kind.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/Kind.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/Kind.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.delta;
+
+/**
+ * The kind of the {@link INlpElementDelta}.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.1.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public enum Kind {
+ /**
+ * Added a resource.
+ */
+ ADDED,
+
+ /**
+ * Removed a resource.
+ */
+ REMOVED,
+
+ /**
+ * Chnaged a resource or one of its childs.
+ */
+ CHANGED;
+}
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/NlpModelDeltaImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/NlpModelDeltaImpl.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/NlpModelDeltaImpl.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/delta/NlpModelDeltaImpl.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.delta;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+
+/**
+ * The internal implementation of the nlp model delta interface.
+ *
+ * TODO: Add a filter to avoid node with Kind.NOTHING.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.5.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public final class NlpModelDeltaImpl implements INlpElementDelta {
+ private IResourceDelta mResourceDelta;
+
+ private Collection<INlpElementDelta> mChildren = new LinkedList<INlpElementDelta>();
+
+ private INlpElement mNlpElement;
+
+ /**
+ * The kind of the event. After an project was opened the old closed project (closed project does
+ * not have a natures) must be removed. Then the newly created NlpProject will be added. For this
+ * add the kind must be changed from changed to added. To have control about the kind the status
+ * is duplicated here.
+ */
+ private Kind mKind;
+
+ private NlpModelDeltaImpl mParent;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param parent
+ * @param resourceDelta
+ */
+ public NlpModelDeltaImpl(NlpModelDeltaImpl parent, IResourceDelta resourceDelta) {
+ mParent = parent;
+
+ mResourceDelta = resourceDelta;
+
+ mKind = getKind(resourceDelta);
+
+ IResourceDelta deltas[] = mResourceDelta.getAffectedChildren();
+
+ for (int i = 0; i < deltas.length; i++) {
+ mChildren.add(new NlpModelDeltaImpl(this, deltas[i]));
+ }
+ }
+
+ /**
+ * Sets the nlp element Note: do not call this method from ouside code
+ *
+ * @param element
+ */
+ public void setNlpElement(INlpElement element) {
+ mNlpElement = element;
+ }
+
+ /**
+ * Retrives the parent element or null if this is the root delta.
+ *
+ * @return parent element or null
+ */
+ public INlpElementDelta getParent() {
+ return mParent;
+ }
+
+ /**
+ * Adds a child to the current element instance.
+ *
+ * @param child
+ */
+ public void addChild(NlpModelDeltaImpl child) {
+ mChildren.add(child);
+ }
+
+ /**
+ * Accepts the given visitor.
+ */
+ public void accept(INlpModelDeltaVisitor visitor) {
+ boolean wantsToVisitChilds = visitor.visit(this);
+
+ if (wantsToVisitChilds) {
+ for (INlpElementDelta delta : getAffectedChildren()) {
+ delta.accept(visitor);
+ }
+ }
+ }
+
+ /**
+ * Retrives the affected children.
+ */
+ public INlpElementDelta[] getAffectedChildren() {
+ return mChildren.toArray(new INlpElementDelta[mChildren.size()]);
+ }
+
+ /**
+ * Checks if the current instance is a nlp element.
+ */
+ public boolean isNlpElement() {
+ return mNlpElement != null;
+ }
+
+ /**
+ * Retrives the nlp element.
+ */
+ public INlpElement getNlpElement() {
+ return mNlpElement;
+ }
+
+ /**
+ * Retrives the resource.
+ */
+ public IResource getResource() {
+ return mResourceDelta.getResource();
+ }
+
+ /**
+ * Retrives the kind
+ */
+ public Kind getKind() {
+ return mKind;
+ }
+
+ /**
+ * Sets the new kind. This method should only be called from the event handlers snd not by any
+ * client.
+ *
+ * @param kind
+ */
+ public void setKind(Kind kind) {
+ mKind = kind;
+ }
+
+ /**
+ * Retrives the original flags of the {@link IResourceDelta} object.
+ */
+ public int getFlags() {
+ return mResourceDelta.getFlags();
+ }
+
+ /**
+ * Retrives the resource delta.
+ *
+ * @return the resource delta
+ */
+ public IResourceDelta getResourceDelta() {
+ return mResourceDelta;
+ }
+
+ /**
+ * Retrives a human-readable string of the current instance.
+ */
+ @Override
+ public String toString() {
+ return (isNlpElement() ? "Nlp: " : "") + mResourceDelta.toString();
+ }
+
+ private static Kind getKind(IResourceDelta delta) {
+ Kind kind;
+
+ if ((delta.getKind() & (IResourceDelta.ADDED | IResourceDelta.ADDED_PHANTOM)) != 0) {
+ kind = Kind.ADDED;
+ } else if ((delta.getKind() & (IResourceDelta.REMOVED | IResourceDelta.REMOVED_PHANTOM)) != 0) {
+ kind = Kind.REMOVED;
+ } else if ((delta.getKind() & IResourceDelta.CHANGED) != 0) {
+ kind = Kind.CHANGED;
+ } else {
+ kind = null;
+ }
+
+ return kind;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/AnnotationStyle.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/AnnotationStyle.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/AnnotationStyle.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/AnnotationStyle.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.dotcorpus;
+
+import java.awt.Color;
+
+/**
+ * The <code>AnnotationStyle</code> describes the look of an certain annotation type in the
+ * <code>AnnotationEditor</code>.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.2.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public final class AnnotationStyle {
+ /**
+ * The styles that can be used to draw an annotation.
+ */
+ public enum Style {
+ /**
+ * The squiggles style.
+ */
+ SQUIGGLES,
+
+ /**
+ * The box style.
+ */
+ BOX,
+
+ /**
+ * The underline style.
+ */
+ UNDERLINE,
+
+ /**
+ * The bracket style.
+ */
+ BRACKET
+ }
+
+ /**
+ * The default <code>DrawingStyle<code>.
+ */
+ public static final Style DEFAULT_STYLE = Style.SQUIGGLES;
+
+ /**
+ * The default drawing color.
+ */
+ public static final java.awt.Color DEFAULT_COLOR = java.awt.Color.RED;
+
+ private String mAnnotation;
+
+ private Style mStyle;
+
+ private Color mColor;
+
+ /**
+ * Initialize a new instance.
+ *
+ * @param annotation -
+ * the annotation type
+ * @param style -
+ * the drawing style
+ * @param color -
+ * annotation color
+ */
+ public AnnotationStyle(String annotation, Style style, Color color) {
+ // annoatation
+ if (annotation == null) {
+ throw new IllegalArgumentException("annotation must be not null!");
+ }
+
+ mAnnotation = annotation;
+
+ // style
+ if (style == null) {
+ throw new IllegalArgumentException("style must be not null!");
+ }
+
+ mStyle = style;
+
+ // color
+ if (color == null) {
+ throw new IllegalArgumentException("color must be not null!");
+ }
+
+ mColor = color;
+ }
+
+ /**
+ * Retrives the annoation type.
+ *
+ * @return - annotation type.
+ */
+ public String getAnnotation() {
+ return mAnnotation;
+ }
+
+ /**
+ * Retrives the drawing style of the annotation.
+ *
+ * @return - annotation drawing style
+ */
+ public Style getStyle() {
+ return mStyle;
+ }
+
+ /**
+ * Retrives the color of the annotation.
+ *
+ * @return - annotation color
+ */
+ public Color getColor() {
+ return mColor;
+ }
+
+ /**
+ * Compares if current is equal to another object.
+ */
+ @Override
+ public boolean equals(Object object) {
+ boolean isEqual;
+
+ if (object != this) {
+ if (object instanceof AnnotationStyle) {
+ AnnotationStyle style = (AnnotationStyle) object;
+
+ isEqual = mAnnotation.equals(style.mAnnotation) && mStyle.equals(style.mStyle)
+ && mColor.equals(style.mColor);
+ } else {
+ isEqual = false;
+ }
+ } else {
+ isEqual = true;
+ }
+
+ return isEqual;
+ }
+
+ /**
+ * Generates a hash code using of toString()
+ */
+ @Override
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ /**
+ * Represents this object as string.
+ */
+ @Override
+ public String toString() {
+ String annotationStyle = "Type: " + mAnnotation;
+ annotationStyle += " Style: " + mStyle.name();
+ annotationStyle += " Color: " + mColor.toString();
+
+ return annotationStyle;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.dotcorpus;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.uima.cas.Type;
+
+/**
+ * This class contains all project specific configuration parameters. Note: Use DotCorpusSerialzer
+ * to read or write an instance of this class to or from a byte stream.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.4.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class DotCorpus {
+ /**
+ * The default value for editor line length hint
+ */
+ public static final int EDITOR_LINE_LENGTH_HINT_DEFAULT = 80;
+
+ /**
+ * Name of the typesystem file
+ */
+ private String mTypeSystemFileName;
+
+ /**
+ * names of the corpus folders
+ */
+ private Set<String> mCorpusFolders = new HashSet<String>();
+
+ /**
+ * Names of the configuration source folders
+ */
+ private String mUimaConfigFolder;
+
+ /**
+ * Length hint of the lines in the editor.
+ */
+ private int mEditorLineLengthHint = EDITOR_LINE_LENGTH_HINT_DEFAULT;
+
+ /**
+ * Maps style names to style objects.
+ */
+ private HashMap<String, AnnotationStyle> mStyleMap = new HashMap<String, AnnotationStyle>();
+
+ /**
+ * Retrives type system name parameter.
+ *
+ * @return type system name parameter
+ */
+ public String getTypeSystemFileName() {
+ return mTypeSystemFileName;
+ }
+
+ /**
+ * Sets type system name parameter.
+ *
+ * @param name
+ * type system name parameter
+ */
+ public void setTypeSystemFilename(String name) {
+ mTypeSystemFileName = name;
+ }
+
+ /**
+ * Retrvies the uima config folder name parameter.
+ *
+ * @return uima config folder name parameter.
+ */
+ public String getUimaConfigFolder() {
+ return mUimaConfigFolder;
+ }
+
+ /**
+ * Sets the uima config folder name parameter.
+ *
+ * @param folder
+ * uima config folder name parameter.
+ */
+ public void setUimaConfigFolderName(String folder) {
+ mUimaConfigFolder = folder;
+ }
+
+ /**
+ * Adds a corpus folder
+ *
+ * @param name
+ */
+ public void addCorpusFolder(String name) {
+ mCorpusFolders.add(name);
+ }
+
+ /**
+ * Removes the given corpus folder.
+ *
+ * @param name
+ */
+ public void removeCorpusFolder(String name) {
+ mCorpusFolders.remove(name);
+ }
+
+ /**
+ * Retrives the list of all corpus fodlers.
+ *
+ * @return corpus folder list
+ */
+ public Collection<String> getCorpusFolderNameList() {
+ return Collections.unmodifiableCollection(mCorpusFolders);
+ }
+
+ /**
+ * Retrvies the editor line length hint parameter.
+ *
+ * @return line length hint
+ */
+ public int getEditorLineLengthHint() {
+ return mEditorLineLengthHint;
+ }
+
+ /**
+ * Sets the editor line length hint parameter.
+ *
+ * @param lineLengthHint
+ */
+ public void setEditorLineLength(int lineLengthHint) {
+ mEditorLineLengthHint = lineLengthHint;
+ }
+
+ /**
+ * Retrives the annotation styles.
+ *
+ * @return - the annoation styles
+ */
+ public Collection<AnnotationStyle> getAnnotationStyles() {
+ return mStyleMap.values();
+ }
+
+ /**
+ * Adds an AnnotationStyle. TODO: move style stuff to nlp project
+ *
+ * @param style
+ */
+ public void setStyle(AnnotationStyle style) {
+ if (!(AnnotationStyle.DEFAULT_COLOR.equals(style.getColor()) && AnnotationStyle.DEFAULT_STYLE
+ .equals(style.getStyle()))) {
+ mStyleMap.put(style.getAnnotation(), style);
+ } else {
+ mStyleMap.remove(style.getAnnotation());
+ }
+ }
+
+ /**
+ * Removes an AnnotationStyle for the given name, does nothing if not existent.
+ *
+ * @param name
+ */
+ public void removeStyle(String name) {
+ mStyleMap.remove(name);
+ }
+
+ /**
+ * Retrives the AnnotationStyle for the given type or null if not available.
+ *
+ * @param type
+ * @return the requested style or null if none
+ */
+ public AnnotationStyle getAnnotation(Type type) {
+ AnnotationStyle style = mStyleMap.get(type.getName());
+
+ if (style == null) {
+ style = new AnnotationStyle(type.getName(), AnnotationStyle.DEFAULT_STYLE,
+ AnnotationStyle.DEFAULT_COLOR);
+ }
+
+ return style;
+ }
+
+ /**
+ * Checks if the given object is equal to the current instance.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+
+ if (obj != null && obj instanceof DotCorpus) {
+
+ DotCorpus corpus = (DotCorpus) obj;
+
+ return isEqual(mTypeSystemFileName, corpus.mTypeSystemFileName)
+ && isEqual(mCorpusFolders, corpus.mCorpusFolders)
+ && isEqual(mUimaConfigFolder, corpus.mUimaConfigFolder)
+ && isEqual(mStyleMap, corpus.mStyleMap)
+ && isEqual(mEditorLineLengthHint, corpus.mEditorLineLengthHint);
+ }
+
+ return false;
+ }
+
+ /**
+ * Compares two objects for equality.
+ *
+ * @param a -
+ * the first object or null
+ * @param b -
+ * the secend object or null
+ * @return - a.equals(b) or true if both null
+ */
+ private static boolean isEqual(Object a, Object b) {
+ boolean result;
+
+ if (a != null && b != null) {
+ result = a.equals(b);
+ } else {
+ if (a == null && b == null) {
+ result = true;
+ } else {
+ result = false;
+ }
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,271 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.dotcorpus;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+
+import org.apache.uima.caseditor.core.TaeCorePlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * This class is responsible to read and write {@link DotCorpus} objects from or to a byte stream.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.4.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class DotCorpusSerializer {
+ private static final String CHARSET = "UTF-8";
+
+ private static final String COPORA_ELEMENT = "copora";
+
+ private static final String CORPUS_ELEMENT = "corpus";
+
+ private static final String CORPUS_FOLDER_ATTRIBUTE = "folder";
+
+ private static final String STYLE_ELEMENT = "style";
+
+ private static final String STYLE_TYPE_ATTRIBUTE = "type";
+
+ private static final String STYLE_STYLE_ATTRIBUTE = "style";
+
+ private static final String STYLE_COLOR_ATTRIBUTE = "color";
+
+ private static final String TYPESYSTEM_ELEMENT = "typesystem";
+
+ private static final String TYPESYTEM_FILE_ATTRIBUTE = "file";
+
+ private static final String TAGGER_ELEMENT = "config";
+
+ private static final String TAGGER_FOLDER_ATTRIBUTE = "folder";
+
+ private static final String EDITOR_ELEMENT = "editor";
+
+ private static final String EDITOR_LINE_LENGTH_ATTRIBUTE = "line-length-hint";
+
+ /**
+ * Creats a {@link DotCorpus} object from a given {@link InputStream}.
+ *
+ * @param dotCorpusStream
+ * @return the {@link DotCorpus} instance.
+ * @throws CoreException
+ */
+ public static DotCorpus parseDotCorpus(InputStream dotCorpusStream) throws CoreException {
+ DocumentBuilderFactory documentBuilderFacoty = DocumentBuilderFactory.newInstance();
+
+ DocumentBuilder documentBuilder;
+
+ try {
+ documentBuilder = documentBuilderFacoty.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ String message = ("This should never happen:" + e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+
+ org.w3c.dom.Document dotCorpusDOM;
+
+ try {
+ dotCorpusDOM = documentBuilder.parse(dotCorpusStream);
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (IOException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+
+ DotCorpus dotCorpus = new DotCorpus();
+
+ // get corpora root element
+ Element corporaElement = dotCorpusDOM.getDocumentElement();
+
+ if (COPORA_ELEMENT.equals(corporaElement.getNodeName())) {
+ // TODO:
+ // throw exception
+ }
+
+ NodeList corporaChildNodes = corporaElement.getChildNodes();
+
+ for (int i = 0; i < corporaChildNodes.getLength(); i++) {
+ Node corporaChildNode = corporaChildNodes.item(i);
+
+ if (!(corporaChildNode instanceof Element)) {
+ continue;
+ }
+
+ Element corporaChildElement = (Element) corporaChildNode;
+
+ if (TYPESYSTEM_ELEMENT.equals(corporaChildElement.getNodeName())) {
+ dotCorpus.setTypeSystemFilename(corporaChildElement.getAttribute(TYPESYTEM_FILE_ATTRIBUTE));
+ } else if (CORPUS_ELEMENT.equals(corporaChildElement.getNodeName())) {
+ String corpusFolderName = corporaChildElement.getAttribute(CORPUS_FOLDER_ATTRIBUTE);
+
+ dotCorpus.addCorpusFolder(corpusFolderName);
+ } else if (STYLE_ELEMENT.equals(corporaChildElement.getNodeName())) {
+ String type = corporaChildElement.getAttribute(STYLE_TYPE_ATTRIBUTE);
+
+ String styleString = corporaChildElement.getAttribute(STYLE_STYLE_ATTRIBUTE);
+
+ String colorString = corporaChildElement.getAttribute(STYLE_COLOR_ATTRIBUTE);
+
+ int colorInteger = Integer.parseInt(colorString);
+
+ AnnotationStyle style = new AnnotationStyle(type, AnnotationStyle.Style
+ .valueOf(styleString), new Color(colorInteger));
+
+ dotCorpus.setStyle(style);
+ } else if (TAGGER_ELEMENT.equals(corporaChildElement.getNodeName())) {
+ dotCorpus
+ .setUimaConfigFolderName(corporaChildElement.getAttribute(TAGGER_FOLDER_ATTRIBUTE));
+ } else if (EDITOR_ELEMENT.equals(corporaChildElement.getNodeName())) {
+ String lineLengthHintString = corporaChildElement
+ .getAttribute(EDITOR_LINE_LENGTH_ATTRIBUTE);
+
+ int lineLengthHint = Integer.parseInt(lineLengthHintString);
+
+ dotCorpus.setEditorLineLength(lineLengthHint);
+ } else {
+ String message = ("Unexpected element: " + corporaChildElement.getNodeName());
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, null);
+
+ throw new CoreException(s);
+ }
+ }
+
+ return dotCorpus;
+ }
+
+ /**
+ * Writes the <code>DotCorpus</code> instance to the given <code>OutputStream</code>.
+ *
+ * @param dotCorpus
+ * the {@link DotCorpus} object to serialize.
+ * @param out -
+ * the stream to write the current <code>DotCorpus</code> instance.
+ * @throws CoreException
+ */
+ public static void serialize(DotCorpus dotCorpus, OutputStream out) throws CoreException {
+ OutputStreamWriter writer;
+
+ try {
+ writer = new OutputStreamWriter(out, CHARSET);
+ } catch (UnsupportedEncodingException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+
+ XMLSerializer xmlSerialzer = new XMLSerializer(writer, new OutputFormat("XML", CHARSET, true));
+ try {
+ xmlSerialzer.startDocument();
+ xmlSerialzer.startElement(COPORA_ELEMENT, null);
+
+ for (String corpusFolder : dotCorpus.getCorpusFolderNameList()) {
+ AttributesImpl corpusFolderAttributes = new AttributesImpl();
+ corpusFolderAttributes.addAttribute("", CORPUS_FOLDER_ATTRIBUTE, "", "", corpusFolder);
+
+ xmlSerialzer.startElement("", CORPUS_ELEMENT, "", corpusFolderAttributes);
+ xmlSerialzer.endElement(CORPUS_ELEMENT);
+ }
+
+ for (AnnotationStyle style : dotCorpus.getAnnotationStyles()) {
+ AttributesImpl corpusFolderAttributes = new AttributesImpl();
+ corpusFolderAttributes
+ .addAttribute("", STYLE_TYPE_ATTRIBUTE, "", "", style.getAnnotation());
+ corpusFolderAttributes.addAttribute("", STYLE_STYLE_ATTRIBUTE, "", "", style.getStyle()
+ .name());
+
+ Integer color = style.getColor().getRGB();
+ corpusFolderAttributes.addAttribute("", STYLE_COLOR_ATTRIBUTE, "", "", color.toString());
+
+ xmlSerialzer.startElement("", STYLE_ELEMENT, "", corpusFolderAttributes);
+ xmlSerialzer.endElement(STYLE_ELEMENT);
+
+ }
+
+ if (dotCorpus.getTypeSystemFileName() != null) {
+ AttributesImpl typeSystemFileAttributes = new AttributesImpl();
+ typeSystemFileAttributes.addAttribute("", TYPESYTEM_FILE_ATTRIBUTE, "", "", dotCorpus
+ .getTypeSystemFileName());
+
+ xmlSerialzer.startElement("", TYPESYSTEM_ELEMENT, "", typeSystemFileAttributes);
+ xmlSerialzer.endElement(TYPESYSTEM_ELEMENT);
+ }
+
+ if (dotCorpus.getUimaConfigFolder() != null) {
+ AttributesImpl taggerConfigAttributes = new AttributesImpl();
+ taggerConfigAttributes.addAttribute("", TAGGER_FOLDER_ATTRIBUTE, "", "", dotCorpus
+ .getUimaConfigFolder());
+
+ xmlSerialzer.startElement("", TAGGER_ELEMENT, "", taggerConfigAttributes);
+ xmlSerialzer.endElement(TAGGER_ELEMENT);
+ }
+
+ if (dotCorpus.getEditorLineLengthHint() != DotCorpus.EDITOR_LINE_LENGTH_HINT_DEFAULT) {
+ AttributesImpl editorLineLengthHintAttributes = new AttributesImpl();
+ editorLineLengthHintAttributes.addAttribute("", EDITOR_LINE_LENGTH_ATTRIBUTE, "", "",
+ Integer.toString(dotCorpus.getEditorLineLengthHint()));
+
+ xmlSerialzer.startElement("", EDITOR_ELEMENT, "", editorLineLengthHintAttributes);
+ xmlSerialzer.endElement(EDITOR_ELEMENT);
+ }
+
+ xmlSerialzer.endElement(COPORA_ELEMENT);
+ xmlSerialzer.endDocument();
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/EditorAnnotationStatus.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/EditorAnnotationStatus.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/EditorAnnotationStatus.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/EditorAnnotationStatus.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.model.dotcorpus;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.uima.cas.Type;
+
+/**
+ * TODO: add javadoc here
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.2.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class EditorAnnotationStatus {
+ private Type mMode;
+
+ private Collection<Type> mDisplayAnnotations;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param mode
+ * @param displayAnnotations
+ */
+ public EditorAnnotationStatus(Type mode, Collection<Type> displayAnnotations) {
+ if (mode == null) {
+ throw new IllegalArgumentException("Mode must not be null!");
+ }
+
+ mMode = mode;
+
+ if (displayAnnotations != null) {
+ mDisplayAnnotations = Collections.unmodifiableCollection(displayAnnotations);
+ } else {
+ mDisplayAnnotations = Collections.emptyList();
+ }
+ }
+
+ /**
+ * Retrives the editor mode.
+ *
+ * @return the editor mode
+ */
+ public Type getMode() {
+ return mMode;
+ }
+
+ /**
+ * Retrives the annotations wich a displayed in the editor.
+ *
+ * @return the display annotations
+ */
+ public Collection<Type> getDisplayAnnotations() {
+ return mDisplayAnnotations;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotationComparator.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotationComparator.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotationComparator.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotationComparator.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.uima;
+
+import java.util.Comparator;
+
+import org.apache.uima.cas.text.AnnotationFS;
+
+/**
+ * Checks two annotations for equality.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.3.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class AnnotationComparator implements Comparator<AnnotationFS> {
+ /**
+ * Compares the given annoations a and b. This implementations only compares the begin index.
+ */
+ public int compare(AnnotationFS a, AnnotationFS b) {
+ return a.getBegin() - b.getBegin();
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.uima;
+
+import java.net.MalformedURLException;
+
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.TaeDescription;
+import org.apache.uima.analysis_engine.TextAnalysisEngine;
+import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
+import org.apache.uima.caseditor.core.TaeError;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * TODO: add java doc here
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.3.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class AnnotatorConfiguration {
+ private TaeDescription mDescriptor;
+
+ private IPath mResourceBasePath;
+
+ /**
+ * Initializes the instance.
+ *
+ * @param descriptor
+ */
+ public AnnotatorConfiguration(TaeDescription descriptor) {
+ mDescriptor = descriptor;
+ }
+
+ /**
+ * Retrives the annotator name.
+ *
+ * @return name of the annotator
+ */
+ public String getAnnotatorName() {
+ AnalysisEngineMetaData analysisEngineMetaData = mDescriptor.getAnalysisEngineMetaData();
+
+ return analysisEngineMetaData.getName();
+ }
+
+ /**
+ * Only text analysis engines are supported.
+ *
+ * @return the text analysis engine
+ * @throws ResourceInitializationException
+ */
+ public TextAnalysisEngine createAnnotator() throws ResourceInitializationException {
+ ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
+
+ if (mResourceBasePath != null) {
+ try {
+ // resourceManager.setExtensionClassPath(
+ // mResourceBasePath.toOSString(), true);
+ resourceManager.setDataPath(mResourceBasePath.toOSString());
+ } catch (MalformedURLException e) {
+ // this will not happen
+ throw new TaeError("Unexpexted exceptioon", e);
+ }
+ }
+
+ return UIMAFramework.produceTAE(mDescriptor, resourceManager, null);
+ }
+
+ /**
+ * Sets the base folder
+ *
+ * @param baseFolder
+ */
+ public void setBaseFolder(IFolder baseFolder) {
+ mResourceBasePath = baseFolder.getLocation();
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/CasConsumerConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/CasConsumerConfiguration.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/CasConsumerConfiguration.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/CasConsumerConfiguration.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.uima;
+
+import java.net.MalformedURLException;
+
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.caseditor.core.TaeError;
+import org.apache.uima.caseditor.core.model.ConsumerElement;
+import org.apache.uima.collection.CasConsumer;
+import org.apache.uima.collection.CasConsumerDescription;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * TODO: add javadoc here
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.4.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public final class CasConsumerConfiguration {
+ private CasConsumerDescription mCasConsumerDescriptor;
+
+ private IPath mResoueceBasePath;
+
+ private ConsumerElement mConsumerElement;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param element
+ *
+ * @param descriptor
+ */
+ public CasConsumerConfiguration(ConsumerElement element, CasConsumerDescription descriptor) {
+ mCasConsumerDescriptor = descriptor;
+ mConsumerElement = element;
+ }
+
+ /**
+ * Retrives the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ ProcessingResourceMetaData trainerMetaData = mCasConsumerDescriptor.getCasConsumerMetaData();
+
+ return trainerMetaData.getName();
+ }
+
+ /**
+ * Sets the base folder.
+ *
+ * @param baseFolder
+ */
+ public void setBaseFolder(IFolder baseFolder) {
+ mResoueceBasePath = baseFolder.getLocation();
+ }
+
+ /**
+ * Creates the consumer.
+ *
+ * @return the consumer
+ */
+ public CasConsumer createConsumer() {
+ ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
+
+ if (mResoueceBasePath != null) {
+ try {
+ resourceManager.setExtensionClassPath(mResoueceBasePath.toOSString(), true);
+ resourceManager.setDataPath(mResoueceBasePath.toOSString());
+ } catch (MalformedURLException e) {
+ // this should never happen
+ throw new TaeError("Unexpected exception", e);
+ }
+ }
+
+ try {
+ CasConsumer consumer = UIMAFramework.produceCasConsumer(mCasConsumerDescriptor,
+ resourceManager, null);
+
+ return consumer;
+ } catch (ResourceInitializationException e) {
+
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Retrives the {@link ConsumerElement}.
+ *
+ * @return the {@link ConsumerElement}
+ */
+ public ConsumerElement getConsumerElement() {
+ return mConsumerElement;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/ContainingConstraint.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/ContainingConstraint.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/ContainingConstraint.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/ContainingConstraint.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.uima;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.text.AnnotationFS;
+
+/**
+ * TODO: add javadoc here
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.3.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class ContainingConstraint implements FSMatchConstraint {
+ private static final long serialVersionUID = 1;
+
+ transient private Collection<AnnotationFS> mContainingAnnotations = new LinkedList<AnnotationFS>();
+
+ /**
+ * Adds an annoation in which the an other annotations must be containded to match this
+ * constraint.
+ *
+ * @param containingAnnotation
+ */
+ public void add(AnnotationFS containingAnnotation) {
+ mContainingAnnotations.add(containingAnnotation);
+ }
+
+ /**
+ * Checks if the given FeatureStructure is inside the a containing annoation.
+ */
+ public boolean match(FeatureStructure featureStructure) {
+ boolean result = false;
+
+ if ((featureStructure instanceof AnnotationFS)) {
+ AnnotationFS annotation = (AnnotationFS) featureStructure;
+
+ for (AnnotationFS containingAnnotation : mContainingAnnotations) {
+ if (isContaining(annotation, containingAnnotation)) {
+ result = true;
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private boolean isContaining(AnnotationFS annotation, AnnotationFS containing) {
+ boolean isContaining;
+
+ if ((containing.getBegin() <= annotation.getBegin())
+ && (containing.getEnd() >= annotation.getEnd())) {
+ isContaining = true;
+ } else {
+ isContaining = false;
+ }
+
+ return isContaining;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/DocumentUimaImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/DocumentUimaImpl.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/DocumentUimaImpl.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/DocumentUimaImpl.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.uima;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.ConstraintFactory;
+import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.FSIntConstraint;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.FeaturePath;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.impl.XCASDeserializer;
+import org.apache.uima.cas.impl.XCASSerializer;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.core.AbstractDocument;
+import org.apache.uima.caseditor.core.TaeCorePlugin;
+import org.apache.uima.caseditor.core.model.NlpProject;
+import org.apache.uima.caseditor.core.util.Span;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.xml.sax.SAXException;
+
+/**
+ * TODO: add javdoc here
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.5.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class DocumentUimaImpl extends AbstractDocument {
+ private CAS mCAS;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param project
+ */
+ public DocumentUimaImpl(NlpProject project) {
+ mCAS = project.getTypesystem().getCAS();
+ }
+
+ /**
+ * Retrives the {@link TCAS}.
+ */
+ public CAS getCAS() {
+ return mCAS;
+ }
+
+ /**
+ * Adds the given annotation to the {@link TCAS}.
+ */
+ public void addFeatureStructure(FeatureStructure annotation) {
+ mCAS.getIndexRepository().addFS(annotation);
+
+ fireAddedAnnotation(annotation);
+ }
+
+ /**
+ *
+ */
+ public void addFeatureStructures(Collection<FeatureStructure> annotations) {
+ for (FeatureStructure annotation : annotations) {
+ addFeatureStructure(annotation);
+ }
+ }
+
+ /**
+ * Remove all annotations. TODO: implement it
+ */
+ public void removeAnnotation() {
+ // must be implemented
+ }
+
+ /**
+ * Internally removes an annoation from the {@link TCAS}.
+ *
+ * @param featureStructure
+ */
+ private void removeAnnotationInternal(FeatureStructure featureStructure) {
+ getCAS().getIndexRepository().removeFS(featureStructure);
+ }
+
+ /**
+ * Removes the annoations from the {@link TCAS}.
+ */
+ public void removeFeatureStructure(FeatureStructure annotation) {
+ removeAnnotationInternal(annotation);
+
+ fireRemovedAnnotation(annotation);
+ }
+
+ /**
+ * Removes the given annotations from the {@link TCAS}.
+ */
+ public void removeFeatureStructures(Collection<FeatureStructure> annotationsToRemove) {
+ for (FeatureStructure annotationToRemove : annotationsToRemove) {
+ removeAnnotationInternal(annotationToRemove);
+ }
+
+ fireRemovedAnnotations(annotationsToRemove);
+ }
+
+ /**
+ * Notifies clients about the changed annotation.
+ */
+ public void update(FeatureStructure annotation) {
+ fireUpdatedFeatureStructure(annotation);
+ }
+
+ /**
+ * Notifies clients about the changed annotation.
+ */
+ public void updateFeatureStructure(Collection<FeatureStructure> annotations) {
+ fireUpdatedFeatureStructures(annotations);
+ }
+
+ /**
+ * Retrives annoations of the given type from the {@link TCAS}.
+ */
+ public Collection<AnnotationFS> getAnnotations(Type type) {
+ FSIndex annotationIndex = mCAS.getAnnotationIndex(type);
+
+ StrictTypeConstraint typeConstrain = new StrictTypeConstraint(type);
+
+ FSIterator strictTypeIterator = mCAS.createFilteredIterator(annotationIndex.iterator(),
+ typeConstrain);
+
+ return fsIteratorToCollection(strictTypeIterator);
+ }
+
+ private Collection<AnnotationFS> fsIteratorToCollection(FSIterator iterator) {
+ LinkedList<AnnotationFS> annotations = new LinkedList<AnnotationFS>();
+ while (iterator.hasNext()) {
+ AnnotationFS annotation = (AnnotationFS) iterator.next();
+
+ annotations.addFirst(annotation);
+ }
+
+ return annotations;
+ }
+
+ /**
+ * Retrives the annotations in the given span.
+ */
+ @Override
+ public Collection<AnnotationFS> getAnnotation(Type type, Span span) {
+ ConstraintFactory cf = getCAS().getConstraintFactory();
+
+ Type annotationType = getCAS().getAnnotationType();
+
+ FeaturePath beginPath = getCAS().createFeaturePath();
+ beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
+ FSIntConstraint beginConstraint = cf.createIntConstraint();
+ beginConstraint.geq(span.getStart());
+
+ FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath, beginConstraint);
+
+ FeaturePath endPath = getCAS().createFeaturePath();
+ endPath.addFeature(annotationType.getFeatureByBaseName("end"));
+ FSIntConstraint endConstraint = cf.createIntConstraint();
+ endConstraint.leq(span.getEnd());
+
+ FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath, endConstraint);
+
+ FSMatchConstraint strictType = new StrictTypeConstraint(type);
+
+ FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin, embeddedEnd);
+
+ FSMatchConstraint annotationInSpanAndStrictTypeConstraint = cf.and(annotatioInSpanConstraint,
+ strictType);
+
+ FSIndex allAnnotations = getCAS().getAnnotationIndex(type);
+
+ FSIterator annotationInsideSpanIndex = getCAS().createFilteredIterator(
+ allAnnotations.iterator(), annotationInSpanAndStrictTypeConstraint);
+
+ return fsIteratorToCollection(annotationInsideSpanIndex);
+ }
+
+ /**
+ * Retrives the given type from the {@link TypeSystem}.
+ */
+ public Type getType(String type) {
+ return getCAS().getTypeSystem().getType(type);
+ }
+
+ /**
+ * Retrvies the text.
+ */
+ public String getText() {
+ return mCAS.getDocumentText();
+ }
+
+ /**
+ * Sets the content. The XCAS {@link InputStream} gets parsed.
+ */
+ public void setContent(InputStream content) throws CoreException {
+ XCASDeserializer dezerializer = new XCASDeserializer(mCAS.getTypeSystem());
+
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setValidating(false);
+
+ SAXParser saxParser;
+
+ try {
+ saxParser = saxParserFactory.newSAXParser();
+ saxParser.parse(content, dezerializer.getXCASHandler(mCAS));
+ } catch (IOException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (ParserConfigurationException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+ }
+
+ /**
+ * Serializes the {@link CAS} to the given {@link OutputStream} in the XCAS format.
+ */
+ public void serialize(OutputStream out) throws CoreException {
+
+ try {
+ XCASSerializer.serialize(mCAS, out);
+ } catch (IOException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, TaeCorePlugin.ID, IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/StrictTypeConstraint.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/StrictTypeConstraint.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/StrictTypeConstraint.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/StrictTypeConstraint.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.uima;
+
+import org.apache.uima.cas.FSConstraint;
+import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+
+/**
+ * Matches all annoations of an added type.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.3.2.2 $, $Date: 2007/01/04 14:56:24 $
+ */
+public class StrictTypeConstraint implements FSConstraint, FSMatchConstraint {
+ private static final long serialVersionUID = 1;
+
+ private Type mMatch;
+
+ /**
+ * Initializes the current instance.
+ *
+ * @param match
+ */
+ public StrictTypeConstraint(Type match) {
+ mMatch = match;
+ }
+
+ /**
+ * Chekcs if the given {@link FeatureStructure} matchs this constraint.
+ */
+ public boolean match(FeatureStructure candidateFS) {
+ return candidateFS.getType().getName().equals(mMatch.getName());
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/EventDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/EventDispatcher.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/EventDispatcher.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/EventDispatcher.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The EventDispatcher routs received events to the registered handler objects.
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.2.2.2 $, $Date: 2007/01/04 14:56:26 $
+ * @param <K>
+ * the key type
+ * @param <E>
+ * the event type
+ */
+public class EventDispatcher<K, E> {
+ private Map<K, IEventHandler<E>> mHandler = new HashMap<K, IEventHandler<E>>();
+
+ private IEventHandler<E> mDefaultHandler;
+
+ /**
+ * Initializes the current instance with a default handler.
+ *
+ * @param defaultHandler
+ * handles all unkown events, must not be null
+ */
+ public EventDispatcher(IEventHandler<E> defaultHandler) {
+ if (defaultHandler == null) {
+ throw new IllegalArgumentException("The defaultHandler must not be null!");
+ }
+
+ mDefaultHandler = defaultHandler;
+ }
+
+ /**
+ * Registers the given handler for the given key.
+ *
+ * @param key
+ * @param handler
+ */
+ public void register(K key, IEventHandler<E> handler) {
+ mHandler.put(key, handler);
+ }
+
+ /**
+ * Notifies the registered handler, if there is no handler registered for this key the default
+ * handler is notified.
+ *
+ * @param key
+ * the key type
+ * @param event
+ * the event type
+ */
+ public void notify(K key, E event) {
+ IEventHandler<E> handler = mHandler.get(key);
+
+ if (handler != null) {
+ handler.handle(event);
+ } else {
+ mDefaultHandler.handle(event);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IDGenerator.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IDGenerator.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IDGenerator.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IDGenerator.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.util;
+
+import java.util.Random;
+
+/**
+ * <p>
+ * The IDGenerator generate unique IDs.
+ * </p>
+ * <p>
+ * Attention: The maximal number of generateable IDs is Long.MAX_VALUE. If there are more than
+ * Long.MAX_VALUE calls to nextUniqueID() an IllegalStateException will be thrown.
+ * </p>
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.3.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public class IDGenerator {
+ private long sStartValue;
+
+ /**
+ * The unique id that will be incremented.
+ */
+ private long sUniqueID = sStartValue + 1;
+
+ /**
+ * The singleton instance.
+ */
+ private static IDGenerator sIdGeneratorInstance;
+
+ /**
+ * Call <code>IDGenerator.getInstance()</code> to retrive an instance of this class. Must not be
+ * instanciated outside this class, singleton pattern.
+ */
+ private IDGenerator() {
+ sStartValue = new Random().nextLong();
+ }
+
+ /**
+ * Retrive the next unique ID.
+ *
+ * @throws IllegalStateException -
+ * if there are more than Long.MAX_VALUE calls to
+ * <code>IDGenerator.nextUniqueID()</code>
+ * @return - the unique id
+ */
+ public byte[] nextUniqueID() {
+ if (sUniqueID == sStartValue) {
+ throw new IllegalStateException("The ID Generator is out of IDs");
+ }
+
+ byte[] id = new byte[] { (byte) (sUniqueID >> 56), (byte) (sUniqueID >> 48),
+ (byte) (sUniqueID >> 40), (byte) (sUniqueID >> 32), (byte) (sUniqueID >> 24),
+ (byte) (sUniqueID >> 16), (byte) (sUniqueID >> 8), (byte) sUniqueID, };
+
+ sUniqueID++;
+ return id;
+ }
+
+ /**
+ * Retrives the only instance of the IDGenerator.
+ *
+ * @return - the instance of the IDGenerator
+ */
+ public static IDGenerator getInstance() {
+ if (sIdGeneratorInstance == null) {
+ sIdGeneratorInstance = new IDGenerator();
+ }
+
+ return sIdGeneratorInstance;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IEventHandler.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IEventHandler.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/IEventHandler.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.util;
+
+/**
+ * Clients which implement this interface can receive event notifications from the
+ * {@link EventDispatcher} after registering the handler for an specific event type.
+ *
+ * @param <E>
+ * the event object type
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.2.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public interface IEventHandler<E> {
+ /**
+ * This method is called to handle the given event.
+ *
+ * @param event
+ * the event to handle
+ */
+ void handle(E event);
+}
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/MarkerUtil.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/MarkerUtil.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/MarkerUtil.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/util/MarkerUtil.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.util;
+
+import org.apache.uima.util.InvalidXMLException;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * TODO: add javadoc here
+ *
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.4.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public final class MarkerUtil {
+ /**
+ * ID of the problem marker.
+ */
+ public static final String PROBLEM_MARKER = "net.sf.tae.core.problem";
+
+ private MarkerUtil() {
+ // util class
+ }
+
+ /**
+ * Clears all markers of the given id for the given resource.
+ *
+ * @param resource
+ * @param markerId
+ * @throws CoreException
+ */
+ public static void clearMarkers(IResource resource, String markerId) throws CoreException {
+ if (resource.exists()) {
+ IMarker[] markers = resource.findMarkers(markerId, false, 0);
+
+ for (IMarker marker : markers) {
+ marker.delete();
+ }
+ }
+ }
+
+ /**
+ * Creates a new marker.
+ *
+ * @param resource
+ * @param errorMessage
+ * @throws CoreException
+ */
+ public static void createMarker(IResource resource, String errorMessage) throws CoreException {
+ IMarker marker = resource.createMarker(PROBLEM_MARKER);
+
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ marker.setAttribute(IMarker.MARKER, IMarker.PROBLEM);
+
+ marker.setAttribute(IMarker.MESSAGE, errorMessage);
+ marker.setAttribute(IMarker.LINE_NUMBER, 1);
+ }
+
+ /**
+ * Creates a new marker.
+ *
+ * @param resource
+ * @param xmlException
+ * @throws CoreException
+ */
+ public static void createMarker(IResource resource, InvalidXMLException xmlException)
+ throws CoreException {
+ IMarker marker = resource.createMarker(PROBLEM_MARKER);
+
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ marker.setAttribute(IMarker.MARKER, IMarker.PROBLEM);
+
+ Throwable causeException = xmlException.getCause();
+
+ if (causeException instanceof SAXParseException) {
+ SAXParseException parseException = (SAXParseException) causeException;
+
+ marker.setAttribute(IMarker.MESSAGE, parseException.getMessage());
+ marker.setAttribute(IMarker.LINE_NUMBER, parseException.getLineNumber());
+ } else {
+ marker.setAttribute(IMarker.MESSAGE, xmlException.getMessage());
+ }
+ }
+}
\ No newline at end of file