|
From: <lh...@us...> - 2009-04-03 11:35:42
|
Revision: 294
http://tinytim.svn.sourceforge.net/tinytim/?rev=294&view=rev
Author: lheuer
Date: 2009-04-03 11:35:36 +0000 (Fri, 03 Apr 2009)
Log Message:
-----------
Initial import of the schema interfaces
Added Paths:
-----------
tinytim-schema/
tinytim-schema/branches/
tinytim-schema/tags/
tinytim-schema/trunk/
tinytim-schema/trunk/src/
tinytim-schema/trunk/src/main/
tinytim-schema/trunk/src/main/java/
tinytim-schema/trunk/src/main/java/org/
tinytim-schema/trunk/src/main/java/org/tinytim/
tinytim-schema/trunk/src/main/java/org/tinytim/schema/
tinytim-schema/trunk/src/main/java/org/tinytim/schema/Schema.java
tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaErrorHandler.java
tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaException.java
tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaReader.java
tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaValidator.java
tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaViolationException.java
Added: tinytim-schema/trunk/src/main/java/org/tinytim/schema/Schema.java
===================================================================
--- tinytim-schema/trunk/src/main/java/org/tinytim/schema/Schema.java (rev 0)
+++ tinytim-schema/trunk/src/main/java/org/tinytim/schema/Schema.java 2009-04-03 11:35:36 UTC (rev 294)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed 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.tinytim.schema;
+
+/**
+ * Representation of an immutable Topic Maps schema.
+ * <p>
+ * A schema represents a set of constraints that can be checked against a
+ * topic map.
+ * </p>
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface Schema {
+
+ /**
+ * Returns a schema validator that is able to validate a topic map against
+ * this schema.
+ *
+ * @return A schema validator.
+ */
+ public SchemaValidator createValidator();
+
+}
Property changes on: tinytim-schema/trunk/src/main/java/org/tinytim/schema/Schema.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaErrorHandler.java
===================================================================
--- tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaErrorHandler.java (rev 0)
+++ tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaErrorHandler.java 2009-04-03 11:35:36 UTC (rev 294)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed 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.tinytim.schema;
+
+import org.tmapi.core.Construct;
+
+/**
+ * Handler which gets notified in case of Topic Maps schema violations.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface SchemaErrorHandler {
+
+ /**
+ * Notification when the validation starts.
+ *
+ * @throws SchemaViolationException In case of an error.
+ */
+ public void startValidation() throws SchemaViolationException;
+
+ /**
+ * Notification when the validation has finished.
+ *
+ * @throws SchemaViolationException In case of an error.
+ */
+ public void endValidation() throws SchemaViolationException;
+
+ /**
+ * Notification when an error has occured.
+ * <p>
+ * The handler may throw a {@link SchemaViolationException} or simply report
+ * the violation (i.e. write a log entry) without forcing the
+ * {@link SchemaValidator} to stop the validation process.
+ * </p>
+ *
+ * @param message The error message.
+ * @param construct The construct which causes the error.
+ * @throws SchemaViolationException Default case.
+ */
+ public void error(String message, Construct construct) throws SchemaViolationException;
+
+}
Property changes on: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaErrorHandler.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaException.java
===================================================================
--- tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaException.java (rev 0)
+++ tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaException.java 2009-04-03 11:35:36 UTC (rev 294)
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed 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.tinytim.schema;
+
+/**
+ * Generic schema-specific exception which may be thrown in case of
+ * schema-related errors (i.e. syntax errors).
+ * <p>
+ * This exception must not be thrown in case of schema violation errors, use
+ * {@link SchemaViolationException} for that purpose.
+ * </p>
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class SchemaException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2670201943956954869L;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param message The message.
+ */
+ public SchemaException(String message) {
+ super(message);
+ }
+
+}
Property changes on: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaException.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaReader.java
===================================================================
--- tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaReader.java (rev 0)
+++ tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaReader.java 2009-04-03 11:35:36 UTC (rev 294)
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed 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.tinytim.schema;
+
+import java.io.IOException;
+
+/**
+ * This interface represents a reader to deserialize a Topic Maps schema from
+ * a source.
+ * <p>
+ * The reader is not meant to be reused and should be thrown away once the
+ * {@link #read()} method was invoked.
+ * </p>
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface SchemaReader {
+
+ /**
+ * Reads a schema.
+ *
+ * @return The read schema.
+ * @throws IOException If an error occurs.
+ * @throws SchemaException If a schema-specific error occurs (i.e. syntax error).
+ */
+ public Schema read() throws IOException, SchemaException;
+
+}
Property changes on: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaReader.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaValidator.java
===================================================================
--- tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaValidator.java (rev 0)
+++ tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaValidator.java 2009-04-03 11:35:36 UTC (rev 294)
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed 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.tinytim.schema;
+
+import org.tmapi.core.TopicMap;
+
+/**
+ * Validates a topic map with respect to a schema. The schema is determined when
+ * the <tt>SchemaValidator</tt> is created and cannot be changed.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface SchemaValidator {
+
+ /**
+ * Returns the underlying error handler.
+ * <p>
+ * If no error handler was set explictly via
+ * {@link #setErrorHandler(SchemaErrorHandler)}, the schema validator
+ * returns a default error handler.
+ * </p>
+ *
+ * @return The error handler instance, never <tt>null</tt>.
+ */
+ public SchemaErrorHandler getErrorHandler();
+
+ /**
+ * Sets the error handler which is used to report errors.
+ * <p>
+ * A previously set error handler will be overridden.
+ * </p>
+ *
+ * @param errorHandler The error handler.
+ */
+ public void setErrorHandler(SchemaErrorHandler errorHandler);
+
+ /**
+ * Validates the topic map against the schema to which this validator
+ * instance is bound to.
+ * <p>
+ * If the schema validator stops at the first error or checks the whole
+ * topic map and reports all found errors depends on the
+ * {@link SchemaErrorHandler}.
+ * </p>
+ *
+ * @param topicMap The topic map to validate.
+ * @throws SchemaViolationException In case of an error.
+ */
+ public void validate(TopicMap topicMap) throws SchemaViolationException;
+
+}
Property changes on: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaValidator.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaViolationException.java
===================================================================
--- tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaViolationException.java (rev 0)
+++ tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaViolationException.java 2009-04-03 11:35:36 UTC (rev 294)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed 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.tinytim.schema;
+
+import org.tmapi.core.Construct;
+
+/**
+ * Exception thrown in case of a schema violation.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class SchemaViolationException extends SchemaException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9188289535093661832L;
+
+ /**
+ * The construct which violates the schema.
+ */
+ private final Construct _construct;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param message The message.
+ * @param construct The construct which violates the schema, must not be <tt>null</tt>.
+ */
+ public SchemaViolationException(String message, Construct construct) {
+ super(message);
+ if (construct == null) {
+ throw new IllegalArgumentException("The construct must not be null");
+ }
+ _construct = construct;
+ }
+
+ /**
+ * Returns the construct which has violates the {@link Schema}.
+ *
+ * @return The construct which violates the schema.
+ */
+ public Construct getConstruct() {
+ return _construct;
+ }
+}
Property changes on: tinytim-schema/trunk/src/main/java/org/tinytim/schema/SchemaViolationException.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|