1.1 --- a/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/InputConfig.java Mon Aug 16 07:45:33 2004 +0000
1.2 +++ b/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/InputConfig.java Tue Aug 17 07:39:45 2004 +0000
1.3 @@ -18,6 +18,7 @@
1.4
1.5 private XMIReferenceResolver resolver = null;
1.6 private XMIHeaderConsumer headerConsumer = null;
1.7 + private boolean ignoreUnknownElements = false;
1.8
1.9 public void setReferenceResolver(XMIReferenceResolver resolver) {
1.10 this.resolver = resolver;
1.11 @@ -36,4 +37,15 @@
1.12 public XMIHeaderConsumer getHeaderConsumer() {
1.13 return headerConsumer;
1.14 }
1.15 +
1.16 + // ..........................................................................
1.17 +
1.18 + public boolean isUnknownElementsIgnored() {
1.19 + return ignoreUnknownElements;
1.20 + }
1.21 +
1.22 + public void setUnknownElementsIgnored(boolean newValue) {
1.23 + ignoreUnknownElements = newValue;
1.24 + }
1.25 +
1.26 }
2.1 --- a/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/XmiContext.java Mon Aug 16 07:45:33 2004 +0000
2.2 +++ b/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/XmiContext.java Tue Aug 17 07:39:45 2004 +0000
2.3 @@ -117,6 +117,8 @@
2.4 boolean isMain = true;
2.5 // set storing systemId's of all already read or currently being read documents
2.6 private Set readDocuments = new HashSet ();
2.7 + // flag indicating whether an unknown elements should be ignored (otherwise a DebugException is thrown)
2.8 + private boolean ignoreUnknownElements = false;
2.9
2.10 // systemId of the currently read document
2.11 private String thisSystemId = null;
2.12 @@ -145,7 +147,7 @@
2.13 this (extents, config);
2.14 this.docURL = docURL;
2.15 if (docURL == null)
2.16 - thisSystemId = "";
2.17 + thisSystemId = ""; // NOI18N
2.18 else
2.19 thisSystemId = docURL.toString ();
2.20 readDocuments.add (thisSystemId);
2.21 @@ -160,6 +162,7 @@
2.22 resolver = this;
2.23 if (config instanceof InputConfig) {
2.24 headerConsumer = ((InputConfig) config).getHeaderConsumer ();
2.25 + ignoreUnknownElements = ((InputConfig) config).isUnknownElementsIgnored();
2.26 }
2.27
2.28 // check if ModelPackage is present among input packages (and store it)
2.29 @@ -514,8 +517,13 @@
2.30 break;
2.31 index = packageName.indexOf (XmiConstants.DOT_SEPARATOR);
2.32 }
2.33 - if (outermostPackage == null)
2.34 - throw new DebugException ("Element name cannot be resolved, unknown package: " + fqName);
2.35 + if (outermostPackage == null) {
2.36 + if (ignoreUnknownElements) {
2.37 + return null;
2.38 + } else {
2.39 + throw new DebugException ("Element name cannot be resolved, unknown package: " + fqName);
2.40 + }
2.41 + }
2.42 StringTokenizer tokenizer = new StringTokenizer (fqName, ".");
2.43 LinkedList nameParts = new LinkedList ();
2.44 tokenizer.nextToken (); // skip the outermost package name
2.45 @@ -541,8 +549,13 @@
2.46 nsPrefixName = fqName.substring (0, pos);
2.47 }
2.48 List packages = (List) namespaces.get (nsPrefixName);
2.49 - if (packages == null)
2.50 - throw new DebugException ("Namespace cannot be resolved: " + nsPrefixName);
2.51 + if (packages == null) {
2.52 + if (ignoreUnknownElements) {
2.53 + return null;
2.54 + } else {
2.55 + throw new DebugException ("Namespace cannot be resolved: " + nsPrefixName);
2.56 + }
2.57 + }
2.58
2.59 int pos2 = fqName.indexOf (XmiConstants.DOT_SEPARATOR);
2.60 Iterator iter = packages.iterator ();
2.61 @@ -573,8 +586,13 @@
2.62
2.63 } // else
2.64
2.65 - if (result == null)
2.66 - throw new DebugException("Name cannot be resolved: " + fqName);
2.67 + if (result == null) {
2.68 + if (ignoreUnknownElements) {
2.69 + return null;
2.70 + } else {
2.71 + throw new DebugException("Name cannot be resolved: " + fqName);
2.72 + }
2.73 + }
2.74 resolvedNames_cache.put (fqName, result);
2.75 return result;
2.76 }
2.77 @@ -655,6 +673,9 @@
2.78 return REFERENCE_VALUE;
2.79 }
2.80 Object ref = resolveElementName (qName);
2.81 + if (ref == null && ignoreUnknownElements) {
2.82 + return new XmiElement.Dummy(parent);
2.83 + }
2.84 if (ref instanceof DataTypeClass) {
2.85 // ===================================
2.86 // MOF 1.3 compatibility
2.87 @@ -1078,6 +1099,10 @@
2.88 throw new DebugException ("Type not resolved: " + type.getName ());
2.89 }
2.90
2.91 + public boolean ignoreUnknownElements() {
2.92 + return ignoreUnknownElements;
2.93 + }
2.94 +
2.95 /**
2.96 * Returns default value for a given attribute.
2.97 */
2.98 @@ -1139,7 +1164,7 @@
2.99 multiValue.add (baseValue);
2.100 return multiValue;
2.101 }
2.102 -
2.103 +
2.104 // ==========================================================================
2.105 // Corba types resolving
2.106 // ==========================================================================
3.1 --- a/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/XmiElement.java Mon Aug 16 07:45:33 2004 +0000
3.2 +++ b/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/XmiElement.java Tue Aug 17 07:39:45 2004 +0000
3.3 @@ -123,7 +123,11 @@
3.4 } else if (qName.equals (XmiConstants.XMI_HEADER)) {
3.5 return new XmiElement.Header (this, context);
3.6 } else {
3.7 - throw new DebugException("Invalid element name: " + qName);
3.8 + if (context.ignoreUnknownElements()) {
3.9 + return new XmiElement.Dummy(this);
3.10 + } else {
3.11 + throw new DebugException("Invalid element name: " + qName);
3.12 + }
3.13 }
3.14 }
3.15 }
3.16 @@ -348,6 +352,9 @@
3.17
3.18 public XmiElement startSubElement (String qName, Attributes attrs) {
3.19 Object ref = context.resolveElementName (qName);
3.20 + if ((ref == null) && context.ignoreUnknownElements()) {
3.21 + return new XmiElement.Dummy(this);
3.22 + }
3.23 // [TODO] resolved 'ref' value can be passed to constructors of sub-elements
3.24 if (ref instanceof RefClass)
3.25 return context.resolveInstanceOrReference (this, qName, attrs);
3.26 @@ -493,13 +500,16 @@
3.27
3.28 public XmiElement startSubElement (String qName, Attributes attrs) {
3.29 Object ref = context.resolveElementName (qName);
3.30 -
3.31 + if (ref == null && context.ignoreUnknownElements()) {
3.32 + return new XmiElement.Dummy(this);
3.33 + }
3.34 +
3.35 if (!(ref instanceof StructuralFeature)) {
3.36 throw new DebugException ("Invalid sub-element: " + qName);
3.37 }
3.38 currentFeature = (StructuralFeature) ref;
3.39 if (currentFeature.getScope ().equals (ScopeKindEnum.CLASSIFIER_LEVEL) && !context.isXmi20) {
3.40 - throw new DebugException ("An instance serialization conitains value of static attribute: " + currentFeature.getName ());
3.41 + throw new DebugException ("An instance serialization contains value of static attribute: " + currentFeature.getName ());
3.42 }
3.43
3.44 if (currentFeature instanceof Attribute) {
3.45 @@ -1562,6 +1572,33 @@
3.46 } // ReferenceValue
3.47
3.48 // **************************************************************************
3.49 + // Dummy
3.50 + // **************************************************************************
3.51 + public static class Dummy extends XmiElement {
3.52 +
3.53 + private int level = 0;
3.54 +
3.55 + public Dummy (XmiElement parent) {
3.56 + super (parent, null);
3.57 + }
3.58 +
3.59 + public XmiElement startSubElement (String qName, Attributes attrs) {
3.60 + level++;
3.61 + return this;
3.62 + }
3.63 +
3.64 + public XmiElement endElement (String qName) {
3.65 + if (level == 0) {
3.66 + return parent;
3.67 + } else {
3.68 + level--;
3.69 + return this;
3.70 + }
3.71 + }
3.72 +
3.73 + }
3.74 +
3.75 + // **************************************************************************
3.76 // ReferencesCounter
3.77 // **************************************************************************
3.78 public static interface ReferencesCounter {