Package com.microstar.xml

Examples of com.microstar.xml.XmlException


                } else if (reply == ErrorHandler.CANCEL) {
                    // NOTE: Since we have to throw an XmlException for
                    // the exception to be properly handled, we communicate
                    // that it is a user cancellation with the special
                    // string pattern "*** Canceled." in the message.
                    throw new XmlException("*** Canceled.",
                            _currentExternalEntity(), _getLineNumber(),
                            _getColumnNumber());
                }
            }

            // No handler.
            throw new XmlException("XML element \"" + elementName
                    + "\" triggers exception:\n  " + ex.getTargetException(),
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber(), ex.getTargetException());
        } catch (Exception ex) {
            exceptionThrown = true;

            if (_handler != null) {
                int reply = _handler.handleError(
                        _getCurrentElement(elementName), _current, ex);

                if (reply == ErrorHandler.CONTINUE) {
                    _attributes.clear();
                    _attributeNameList.clear();
                    _skipElement = 1;
                    _skipElementName = elementName;
                    return;
                } else if (reply == ErrorHandler.CANCEL) {
                    // Restore the status of change requests.
                    // Execute any change requests that might have been queued
                    // as a consequence of this change request.
                    if (_toplevel != null) {
                        // Set the top level back to the default
                        // found in startDocument.
                        _toplevel
                                .setDeferringChangeRequests(_previousDeferStatus);
                        _toplevel.executeChangeRequests();
                    }

                    // NOTE: Since we have to throw an XmlException for
                    // the exception to be properly handled, we communicate
                    // that it is a user cancellation with the special
                    // string pattern "*** Canceled." in the message.
                    throw new XmlException("*** Canceled.",
                            _currentExternalEntity(), _getLineNumber(),
                            _getColumnNumber());
                }
            }

            // There is no handler.
            // Restore the status of change requests.
            // Execute any change requests that might have been queued
            // as a consequence of this change request.
            if (_toplevel != null) {
                // Set the top level back to the default
                // found in startDocument.
                _toplevel.setDeferringChangeRequests(_previousDeferStatus);
                _toplevel.executeChangeRequests();
            }

            if (ex instanceof XmlException) {
                throw (XmlException) ex;
            } else {
                throw new XmlException("XML element \"" + elementName
                        + "\" triggers exception.", _currentExternalEntity(),
                        _getLineNumber(), _getColumnNumber(), ex);
            }
        } finally {
            _attributes.clear();
View Full Code Here


                } catch (Exception ex3) {
                    // Cannot find a class definition.
                    // Unfortunately exception chaining does not work here
                    // since we really want to know what ex2 and ex3
                    // both were.
                    throw new XmlException("Could not find '" + classAsFile
                            + "' or '" + altClassAsFile + "' using base '"
                            + _base + "': ", _currentExternalEntity(),
                            _getLineNumber(), _getColumnNumber(), ex2);
                }
            } else {
                // No alternative. Rethrow exception.
                throw ex2;
            }
        }

        if (candidateReference instanceof ComponentEntity) {
            reference = (ComponentEntity) candidateReference;
        } else {
            throw new XmlException("File " + classAsFile
                    + " does not define a ComponentEntity.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        // Check that the classname matches the name of the
        // reference.
        String referenceName = reference.getName();

        if (!className.equals(referenceName)
                && !className.endsWith("." + referenceName)) {
            // The className might reference an inner class defined in
            // the reference.  Try to find that.
            if (reference instanceof CompositeEntity) {
                if (className.startsWith(referenceName + ".")) {
                    reference = ((CompositeEntity) reference)
                            .getEntity(className.substring(referenceName
                                    .length() + 1));
                } else {
                    reference = null;
                }
            } else {
                reference = null;
            }
            if (reference == null) {
                throw new XmlException("File " + classAsFile
                        + " does not define a class named " + className,
                        _currentExternalEntity(), _getLineNumber(),
                        _getColumnNumber());
            }
        }
View Full Code Here

    // If the first argument is not an instance of the second,
    // throw an exception with the given message.
    private void _checkClass(Object object, Class correctClass, String msg)
            throws XmlException {
        if (!correctClass.isInstance(object)) {
            throw new XmlException(msg, _currentExternalEntity(),
                    _getLineNumber(), _getColumnNumber());
        }
    }
View Full Code Here

    // If the argument is null, throw an exception with the given message.
    private void _checkForNull(Object object, String message)
            throws XmlException {
        if (object == null) {
            throw new XmlException(message, _currentExternalEntity(),
                    _getLineNumber(), _getColumnNumber());
        }
    }
View Full Code Here

     * @exception Exception
     */
    private NamedObj _createEntity(String className, String entityName,
            String source) throws Exception {
        if ((_current != null) && !(_current instanceof CompositeEntity)) {
            throw new XmlException("Cannot create an entity inside "
                    + "of another that is not a CompositeEntity "
                    + "(Container is '" + _current + "').",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }
View Full Code Here

            if (i < (arguments.length - 1)) {
                argumentBuffer.append(", ");
            }
        }

        throw new XmlException("Cannot find a suitable constructor ("
                + arguments.length + " args) (" + argumentBuffer + ") for '"
                + newClass.getName() + "'", _currentExternalEntity(),
                _getLineNumber(), _getColumnNumber());
    }
View Full Code Here

        if (toDelete == null) {
            return null;
        }

        if (portContainer == null) {
            throw new XmlException("No container for the port: " + portName,
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        // Ensure that derived objects aren't changed.
View Full Code Here

            if (className != null) {
                try {
                    newClass = Class.forName(className, true, _classLoader);
                } catch (NoClassDefFoundError ex) {
                    throw new XmlException("Failed to find class '" + className
                            + "'", _currentExternalEntity(), _getLineNumber(),
                            _getColumnNumber(), ex);
                } catch (SecurityException ex) {
                    // An applet might throw this.
                    throw new XmlException("Failed to find class '" + className
                            + "'", _currentExternalEntity(), _getLineNumber(),
                            _getColumnNumber(), ex);
                }
            }

            // If there is a previous property with this name
            // (property is not null), then we check that the
            // property is an instance of the specified class.
            // If it is, then we set the value of the property.
            // Otherwise, we try to replace it, something that
            // will only work if it is a singleton (it might throw
            // NameDuplicationException).
            boolean previouslyExisted = (property != null);

            // Even if the object previously existed, if the
            // class does not match, we may create a new object.
            boolean createdNew = false;

            // Also need the previous value, if any, to generate undo MoML.
            String oldClassName = null;
            String oldValue = null;

            if (previouslyExisted) {
                oldClassName = property.getClass().getName();

                if (property instanceof Settable) {
                    Settable settable = (Settable) property;
                    oldValue = settable.getExpression();
                }
            }

            if (!previouslyExisted
                    || ((newClass != null) && !newClass.isInstance(property))) {
                // The following will result in a
                // NameDuplicationException if there is a previous
                // property and it is not a singleton.
                try {
                    // No previously existing attribute with this name,
                    // or the class name of the previous entity doesn't
                    // match.
                    if (newClass == null) {
                        newClass = Attribute.class;
                    }

                    // An attribute is not usually a top-level element,
                    // but it might be (e.g. when editing icons).
                    if (_current == null) {
                        // If we want to be able to edit icons, we
                        // have to allow this.
                        // Invoke the constructor.
                        Object[] arguments = new Object[2];
                        arguments[0] = _workspace;
                        arguments[1] = propertyName;
                        property = _createInstance(newClass, arguments);
                        _toplevel = property;
                    } else {
                        // First check that there will be no name collision
                        // when this is propagated. Note that we need to
                        // include all derived objects, irrespective of whether
                        // they are locally changed.
                        List derivedList = _current.getDerivedList();
                        Iterator derivedObjects = derivedList.iterator();

                        while (derivedObjects.hasNext()) {
                            NamedObj derived = (NamedObj) derivedObjects.next();
                            Attribute other = derived
                                    .getAttribute(propertyName);

                            if ((other != null)
                                    && !(other instanceof Singleton)) {
                                throw new IllegalActionException(
                                        _current,
                                        "Cannot create attribute because a subclass or instance "
                                                + "contains an attribute with the same name: "
                                                + derived.getAttribute(
                                                        propertyName)
                                                        .getFullName());
                            }
                        }

                        // Invoke the constructor.
                        Object[] arguments = new Object[2];
                        arguments[0] = _current;
                        arguments[1] = propertyName;
                        property = _createInstance(newClass, arguments);

                        if (property instanceof ptolemy.actor.Director) {
                            _loadIconForClass(className, property);
                        }
                        // Check that the result is an instance of Attribute.
                        if (!(property instanceof Attribute)) {
                            // NOTE: Need to get rid of the object.
                            // Unfortunately, setContainer() is not defined,
                            // so we have to find the right class.
                            if (property instanceof ComponentEntity) {
                                ((ComponentEntity) property).setContainer(null);
                            } else if (property instanceof Port) {
                                ((Port) property).setContainer(null);
                            } else if (property instanceof ComponentRelation) {
                                ((ComponentRelation) property)
                                        .setContainer(null);
                            }

                            throw new XmlException("Property is not an "
                                    + "instance of Attribute. ",
                                    _currentExternalEntity(), _getLineNumber(),
                                    _getColumnNumber());
                        }

                        // Propagate.
                        property.propagateExistence();
                    }

                    if (value != null) {
                        if (property == null) {
                            throw new XmlException("Property does not exist: "
                                    + propertyName + "\n",
                                    _currentExternalEntity(), _getLineNumber(),
                                    _getColumnNumber());
                        }

                        if (!(property instanceof Settable)) {
                            throw new XmlException(
                                    "Property cannot be assigned a value: "
                                            + property.getFullName()
                                            + " (instance of "
                                            + property.getClass().toString()
                                            + ")\n", _currentExternalEntity(),
                                    _getLineNumber(), _getColumnNumber());
                        }

                        Settable settable = (Settable) property;
                        settable.setExpression(value);
                        _paramsToParse.add(property);

                        // Propagate. This has the side effect of marking
                        // the object overridden.
                        property.propagateValue();
                    }

                    createdNew = true;
                } catch (NameDuplicationException ex) {
                    // Ignore, so we can try to set the value.
                    // The createdNew variable will still be false.
                }
            }

            if (!createdNew) {
                // Previously existing property with this name,
                // whose class name exactly matches, or the class
                // name does not match, but a NameDuplicationException
                // was thrown (meaning the attribute was not
                // a singleton).
                // If value is null and the property already
                // exists, then there is nothing to do.
                if (value != null) {
                    if (!(property instanceof Settable)) {
                        throw new XmlException("Property is not an "
                                + "instance of Settable, "
                                + "so can't set the value.",
                                _currentExternalEntity(), _getLineNumber(),
                                _getColumnNumber());
                    }
View Full Code Here

                "Element \"link\" found inside an element that "
                        + "is not a CompositeEntity. It is: " + _current);

        // Check that required arguments are given
        if ((relation1Name == null) || (relation2Name == null)) {
            throw new XmlException("Element link requires two relations.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        CompositeEntity context = (CompositeEntity) _current;
View Full Code Here

        if (relationName != null) {
            countArgs++;
        }

        if (countArgs == 0) {
            throw new XmlException("Element link requires at least one of "
                    + "an insertAt, an insertInsideAt, or a relation.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        if ((insertAtSpec != null) && (insertInsideAtSpec != null)) {
            throw new XmlException("Element link requires at most one of "
                    + "insertAt and insertInsideAt, not both.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }
View Full Code Here

TOP

Related Classes of com.microstar.xml.XmlException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.