Author: rob.stryker(a)jboss.com
Date: 2012-07-25 00:56:48 -0400 (Wed, 25 Jul 2012)
New Revision: 42698
Added:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/IMemento.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLMemento.java
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/.classpath
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/META-INF/MANIFEST.MF
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/build.properties
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModel.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModelRootNode.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/ArchivesUnmarshallerImpl.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/StrictXercesXSMarshaller.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XbPackagesObjectProvider.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/expectedOutputs/emptyPackages.xml
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/validation/MissingFilesetDir.xml
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/projects/JBIDE2439Test.java
Log:
JBIDE-12336 to trunk commit 1
Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/.classpath
===================================================================
--- trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/.classpath 2012-07-24
23:21:29 UTC (rev 42697)
+++ trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/.classpath 2012-07-25
04:56:48 UTC (rev 42698)
@@ -5,12 +5,6 @@
<classpathentry kind="src" path="src/main"/>
<classpathentry kind="src" path="src/xml"/>
<classpathentry kind="src" path="src/eclipse"/>
- <classpathentry exported="true" kind="lib"
path="lib/concurrent-1.3.4.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/jboss-xml-binding.jar"
sourcepath="/home/rob/code/xb/target/jboss-xml-binding-sources.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/xercesImpl-2.9.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/jboss-common-logging-log4j-2.0.4.GA.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/jboss-common-logging-spi-2.0.4.GA.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/jboss-common-core-2.2.1.GA.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/truezip-6.6.jar"
sourcepath="/home/rob/code/truezip/truezip/src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/META-INF/MANIFEST.MF
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/META-INF/MANIFEST.MF 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/META-INF/MANIFEST.MF 2012-07-25
04:56:48 UTC (rev 42698)
@@ -12,17 +12,12 @@
org.eclipse.core.resources;bundle-version="3.7.100",
org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.core.variables;bundle-version="3.2.500",
- org.jboss.tools.usage;resolution:=optional;x-installation:=greedy
+ org.jboss.tools.usage;resolution:=optional;x-installation:=greedy,
+ org.apache.xerces;bundle-version="2.9.0"
Bundle-ActivationPolicy: lazy
Eclipse-BundleShape: dir
Bundle-ClassPath: archivescore.jar,
archivescore-eclipse.jar,
- lib/concurrent-1.3.4.jar,
- lib/jboss-xml-binding.jar,
- lib/xercesImpl-2.9.1.jar,
- lib/jboss-common-logging-log4j-2.0.4.GA.jar,
- lib/jboss-common-logging-spi-2.0.4.GA.jar,
- lib/jboss-common-core-2.2.1.GA.jar,
lib/truezip-6.6.jar
Export-Package:
de.schlichtherle.io;x-friends:="org.jboss.ide.eclipse.archives.test",
de.schlichtherle.io.archive.spi,
Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/build.properties
===================================================================
--- trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/build.properties 2012-07-24
23:21:29 UTC (rev 42697)
+++ trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/build.properties 2012-07-25
04:56:48 UTC (rev 42698)
@@ -5,12 +5,6 @@
LICENSE-truezip.txt,\
log4j.xml,\
archivescore-eclipse.jar,\
- lib/jboss-xml-binding.jar,\
- lib/concurrent-1.3.4.jar,\
- lib/xercesImpl-2.9.1.jar,\
- lib/jboss-common-logging-log4j-2.0.4.GA.jar,\
- lib/jboss-common-logging-spi-2.0.4.GA.jar,\
- lib/jboss-common-core-2.2.1.GA.jar,\
lib/truezip-6.6.jar,\
plugin.properties,\
about.html
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -363,7 +363,8 @@
while(i2.hasNext()) {
try {
IArchive changed = i2.next();
- changedPaths.add(changed.getArchiveFilePath());
+ if( !addedChanged.contains(changed.getArchiveFilePath()))
+ changedPaths.add(changed.getArchiveFilePath());
EventManager.finishedBuildingArchive(changed);
} catch( ClassCastException cce ) {
cce.printStackTrace();
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModel.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModel.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModel.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -12,7 +12,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
/**
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModelRootNode.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModelRootNode.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveModelRootNode.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -12,8 +12,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
/**
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -23,8 +23,8 @@
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
/**
*
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/ArchivesUnmarshallerImpl.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/ArchivesUnmarshallerImpl.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/ArchivesUnmarshallerImpl.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -10,22 +10,7 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.core.model.internal.xb;
-import java.io.InputStream;
-import java.io.Reader;
-import org.jboss.xb.binding.JBossXBException;
-import org.jboss.xb.binding.ObjectModelBuilder;
-import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.metadata.unmarshalling.DocumentBinding;
-import org.jboss.xb.binding.parser.JBossXBParser;
-import org.jboss.xb.binding.parser.sax.SaxJBossXBParser;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
-import org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-
/**
* Unmarshaller implementation.
* WARNING: this implementation is not thread-safe.
@@ -35,168 +20,169 @@
* @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
* @version <tt>$Revision: 2365 $</tt>
*/
-public class ArchivesUnmarshallerImpl implements Unmarshaller {
- private ObjectModelBuilder builder = new ObjectModelBuilder();
- private final JBossXBParser parser;
-
- // Constructor
-
- /**
- * The constructor for DTD and XSD client awareness.
- */
- public ArchivesUnmarshallerImpl() throws JBossXBException {
- parser = new SaxJBossXBParser();
- }
-
- public void setValidation(boolean validation) throws JBossXBException {
- parser.setFeature(VALIDATION, validation);
- /*
- * Only set DYNAMIC_VALIDATION to false. Setting this to true if its not
- * already requires a document to have a DOCTYPE declaring the root
- * element
- */
- if (validation == false)
- parser.setFeature(DYNAMIC_VALIDATION, false);
- }
-
- public void setSchemaValidation(boolean validation) throws JBossXBException {
- parser.setFeature(SCHEMA_VALIDATION, validation);
- }
-
- public void setFeature(String feature, boolean value)
- throws JBossXBException {
- parser.setFeature(feature, value);
- }
-
- public void setNamespaceAware(boolean namespaces) throws JBossXBException {
- parser.setFeature(NAMESPACES, namespaces);
- }
-
- public void setEntityResolver(EntityResolver entityResolver)
- throws JBossXBException {
- parser.setEntityResolver(entityResolver);
- }
-
- public void setErrorHandler(ErrorHandler errorHandler) {
- // todo reader.setErrorHandler(errorHandler);
- }
-
- public void mapFactoryToNamespace(ObjectModelFactory factory,
- String namespaceUri) {
- if (builder == null) {
- builder = new ObjectModelBuilder();
- }
- builder.mapFactoryToNamespace(factory, namespaceUri);
- }
-
- public Object unmarshal(String xmlFile) throws JBossXBException {
- // todo
- throw new UnsupportedOperationException();
- }
-
- public Object unmarshal(String xmlFile, JBossXBParser.ContentHandler handler)
- throws JBossXBException {
- parser.parse(xmlFile, handler);
- return handler.getRoot();
- }
-
- public Object unmarshal(String xml, SchemaBinding schemaBinding)
- throws JBossXBException {
- JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
- schemaBinding);
- parser.parse(xml, cHandler);
- return cHandler.getRoot();
- }
-
- public Object unmarshal(Reader xmlReader, SchemaBinding schemaBinding)
- throws JBossXBException {
- JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
- schemaBinding);
- parser.parse(xmlReader, cHandler);
- return cHandler.getRoot();
- }
-
- public Object unmarshal(InputStream xmlStream, SchemaBinding schemaBinding)
- throws JBossXBException {
- JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
- schemaBinding);
- parser.parse(xmlStream, cHandler);
- return cHandler.getRoot();
- }
-
- public Object unmarshal(String xml, SchemaBindingResolver schemaResolver)
- throws JBossXBException {
- JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
- schemaResolver);
- parser.parse(xml, cHandler);
- return cHandler.getRoot();
- }
-
- public Object unmarshal(Reader xmlReader,
- SchemaBindingResolver schemaResolver) throws JBossXBException {
- JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
- schemaResolver);
- parser.parse(xmlReader, cHandler);
- return cHandler.getRoot();
- }
-
- public Object unmarshal(InputStream xmlStream,
- SchemaBindingResolver schemaResolver) throws JBossXBException {
- JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
- schemaResolver);
- parser.parse(xmlStream, cHandler);
- return cHandler.getRoot();
- }
-
- public Object unmarshal(Reader reader, ObjectModelFactory factory,
- Object root) throws JBossXBException {
- if (builder == null) {
- builder = new ObjectModelBuilder();
- }
- builder.init(factory, root);
- parser.parse(reader, builder);
- return builder.getRoot();
- }
-
- public Object unmarshal(InputStream is, ObjectModelFactory factory,
- Object root) throws JBossXBException {
- if (builder == null) {
- builder = new ObjectModelBuilder();
- }
- builder.init(factory, root);
- parser.parse(is, builder);
- return builder.getRoot();
- }
-
- public Object unmarshal(String systemId, ObjectModelFactory factory,
- Object root) throws JBossXBException {
- if (builder == null) {
- builder = new ObjectModelBuilder();
- }
- builder.init(factory, root);
- parser.parse(systemId, builder);
- return builder.getRoot();
- }
-
- public Object unmarshal(String systemId, ObjectModelFactory factory,
- DocumentBinding binding) throws JBossXBException {
- if (binding != null) {
- throw new IllegalStateException(
- "DocumentBinding API is not supported anymore!"); //$NON-NLS-1$
- }
- return unmarshal(systemId, factory, (Object) null);
- }
-
- public Object unmarshal(Reader reader, ObjectModelFactory factory,
- DocumentBinding binding) throws JBossXBException {
- if (binding != null) {
- throw new IllegalStateException(
- "DocumentBinding API is not supported anymore!"); //$NON-NLS-1$
- }
- return unmarshal(reader, factory, (Object) null);
- }
-
- public JBossXBParser getParser() {
- return parser;
- }
+public class ArchivesUnmarshallerImpl {
+// implements Unmarshaller {
+// private ObjectModelBuilder builder = new ObjectModelBuilder();
+// private final JBossXBParser parser;
+//
+// // Constructor
+//
+// /**
+// * The constructor for DTD and XSD client awareness.
+// */
+// public ArchivesUnmarshallerImpl() throws JBossXBException {
+// parser = new SaxJBossXBParser();
+// }
+//
+// public void setValidation(boolean validation) throws JBossXBException {
+// parser.setFeature(VALIDATION, validation);
+// /*
+// * Only set DYNAMIC_VALIDATION to false. Setting this to true if its not
+// * already requires a document to have a DOCTYPE declaring the root
+// * element
+// */
+// if (validation == false)
+// parser.setFeature(DYNAMIC_VALIDATION, false);
+// }
+//
+// public void setSchemaValidation(boolean validation) throws JBossXBException {
+// parser.setFeature(SCHEMA_VALIDATION, validation);
+// }
+//
+// public void setFeature(String feature, boolean value)
+// throws JBossXBException {
+// parser.setFeature(feature, value);
+// }
+//
+// public void setNamespaceAware(boolean namespaces) throws JBossXBException {
+// parser.setFeature(NAMESPACES, namespaces);
+// }
+//
+// public void setEntityResolver(EntityResolver entityResolver)
+// throws JBossXBException {
+// parser.setEntityResolver(entityResolver);
+// }
+//
+// public void setErrorHandler(ErrorHandler errorHandler) {
+// // todo reader.setErrorHandler(errorHandler);
+// }
+//
+// public void mapFactoryToNamespace(ObjectModelFactory factory,
+// String namespaceUri) {
+// if (builder == null) {
+// builder = new ObjectModelBuilder();
+// }
+// builder.mapFactoryToNamespace(factory, namespaceUri);
+// }
+//
+// public Object unmarshal(String xmlFile) throws JBossXBException {
+// // todo
+// throw new UnsupportedOperationException();
+// }
+//
+// public Object unmarshal(String xmlFile, JBossXBParser.ContentHandler handler)
+// throws JBossXBException {
+// parser.parse(xmlFile, handler);
+// return handler.getRoot();
+// }
+//
+// public Object unmarshal(String xml, SchemaBinding schemaBinding)
+// throws JBossXBException {
+// JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
+// schemaBinding);
+// parser.parse(xml, cHandler);
+// return cHandler.getRoot();
+// }
+//
+// public Object unmarshal(Reader xmlReader, SchemaBinding schemaBinding)
+// throws JBossXBException {
+// JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
+// schemaBinding);
+// parser.parse(xmlReader, cHandler);
+// return cHandler.getRoot();
+// }
+//
+// public Object unmarshal(InputStream xmlStream, SchemaBinding schemaBinding)
+// throws JBossXBException {
+// JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
+// schemaBinding);
+// parser.parse(xmlStream, cHandler);
+// return cHandler.getRoot();
+// }
+//
+// public Object unmarshal(String xml, SchemaBindingResolver schemaResolver)
+// throws JBossXBException {
+// JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
+// schemaResolver);
+// parser.parse(xml, cHandler);
+// return cHandler.getRoot();
+// }
+//
+// public Object unmarshal(Reader xmlReader,
+// SchemaBindingResolver schemaResolver) throws JBossXBException {
+// JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
+// schemaResolver);
+// parser.parse(xmlReader, cHandler);
+// return cHandler.getRoot();
+// }
+//
+// public Object unmarshal(InputStream xmlStream,
+// SchemaBindingResolver schemaResolver) throws JBossXBException {
+// JBossXBParser.ContentHandler cHandler = new SundayContentHandler(
+// schemaResolver);
+// parser.parse(xmlStream, cHandler);
+// return cHandler.getRoot();
+// }
+//
+// public Object unmarshal(Reader reader, ObjectModelFactory factory,
+// Object root) throws JBossXBException {
+// if (builder == null) {
+// builder = new ObjectModelBuilder();
+// }
+// builder.init(factory, root);
+// parser.parse(reader, builder);
+// return builder.getRoot();
+// }
+//
+// public Object unmarshal(InputStream is, ObjectModelFactory factory,
+// Object root) throws JBossXBException {
+// if (builder == null) {
+// builder = new ObjectModelBuilder();
+// }
+// builder.init(factory, root);
+// parser.parse(is, builder);
+// return builder.getRoot();
+// }
+//
+// public Object unmarshal(String systemId, ObjectModelFactory factory,
+// Object root) throws JBossXBException {
+// if (builder == null) {
+// builder = new ObjectModelBuilder();
+// }
+// builder.init(factory, root);
+// parser.parse(systemId, builder);
+// return builder.getRoot();
+// }
+//
+// public Object unmarshal(String systemId, ObjectModelFactory factory,
+// DocumentBinding binding) throws JBossXBException {
+// if (binding != null) {
+// throw new IllegalStateException(
+// "DocumentBinding API is not supported anymore!"); //$NON-NLS-1$
+// }
+// return unmarshal(systemId, factory, (Object) null);
+// }
+//
+// public Object unmarshal(Reader reader, ObjectModelFactory factory,
+// DocumentBinding binding) throws JBossXBException {
+// if (binding != null) {
+// throw new IllegalStateException(
+// "DocumentBinding API is not supported anymore!"); //$NON-NLS-1$
+// }
+// return unmarshal(reader, factory, (Object) null);
+// }
+//
+// public JBossXBParser getParser() {
+// return parser;
+// }
}
Added:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/IMemento.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/IMemento.java
(rev 0)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/IMemento.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Jeff Mesnil
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.jboss.ide.eclipse.archives.core.model.internal.xb;
+
+import java.util.List;
+
+/**
+ * Stolen from webtools wst.server.core,
+ * represents a savable memento to be
+ * translated into xml
+ *
+ * Moved from org.jboss.ide.eclipse.as.core.util.internal
+ * to org.jboss.ide.eclipse.as.core.util
+ *
+ * May later move to COMMON
+ *
+ */
+public interface IMemento {
+ /**
+ * Creates a new child of this memento with the given type.
+ * <p>
+ * The <code>getChild</code> and <code>getChildren</code>
methods
+ * are used to retrieve children of a given type.
+ * </p>
+ *
+ * @param type the type
+ * @return a new child memento
+ * @see #getChild
+ * @see #getChildren
+ */
+ public IMemento createChild(String type);
+
+ /**
+ * Returns the first child with the given type id.
+ *
+ * @param type the type id
+ * @return the first child with the given type
+ */
+ public IMemento getChild(String type);
+
+ /**
+ * Returns all children with the given type id.
+ *
+ * @param type the type id
+ * @return the list of children with the given type
+ */
+ public IMemento[] getChildren(String type);
+
+ /**
+ * Returns the floating point value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was
found
+ * but was not a floating point number
+ */
+ public Float getFloat(String key);
+
+ /**
+ * Returns the integer value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was
found
+ * but was not an integer
+ */
+ public Integer getInteger(String key);
+
+ /**
+ * Returns the string value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was
found
+ * but was not an integer
+ */
+ public String getString(String key);
+
+ /**
+ * Returns the boolean value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was
found
+ * but was not a boolean
+ */
+ public Boolean getBoolean(String key);
+
+ public List<String> getNames();
+
+ /**
+ * Sets the value of the given key to the given integer.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putInteger(String key, int value);
+
+ /**
+ * Sets the value of the given key to the given boolean value.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putBoolean(String key, boolean value);
+
+ /**
+ * Sets the value of the given key to the given string.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putString(String key, String value);
+}
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/StrictXercesXSMarshaller.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/StrictXercesXSMarshaller.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/StrictXercesXSMarshaller.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -10,1451 +10,1402 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.core.model.internal.xb;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.AbstractList;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.xerces.xs.StringList;
-import org.apache.xerces.xs.XSAttributeDeclaration;
-import org.apache.xerces.xs.XSAttributeUse;
-import org.apache.xerces.xs.XSComplexTypeDefinition;
-import org.apache.xerces.xs.XSConstants;
-import org.apache.xerces.xs.XSElementDeclaration;
-import org.apache.xerces.xs.XSModel;
-import org.apache.xerces.xs.XSModelGroup;
-import org.apache.xerces.xs.XSNamedMap;
-import org.apache.xerces.xs.XSObject;
-import org.apache.xerces.xs.XSObjectList;
-import org.apache.xerces.xs.XSParticle;
-import org.apache.xerces.xs.XSSimpleTypeDefinition;
-import org.apache.xerces.xs.XSTerm;
-import org.apache.xerces.xs.XSTypeDefinition;
-import org.apache.xerces.xs.XSWildcard;
-import org.jboss.xb.binding.AbstractMarshaller;
-import org.jboss.xb.binding.AttributesImpl;
-import org.jboss.xb.binding.Constants;
-import org.jboss.xb.binding.Content;
-import org.jboss.xb.binding.ContentWriter;
-import org.jboss.xb.binding.DelegatingObjectModelProvider;
-import org.jboss.xb.binding.GenericObjectModelProvider;
-import org.jboss.xb.binding.JBossXBRuntimeException;
-import org.jboss.xb.binding.Marshaller;
-import org.jboss.xb.binding.MarshallingContext;
-import org.jboss.xb.binding.NamespaceRegistry;
-import org.jboss.xb.binding.ObjectLocalMarshaller;
-import org.jboss.xb.binding.ObjectModelProvider;
-import org.jboss.xb.binding.SimpleTypeBindings;
-import org.jboss.xb.binding.Util;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
/**
* @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
* @version <tt>$Revision: 1958 $</tt>
*/
public class StrictXercesXSMarshaller
- extends AbstractMarshaller
+// extends AbstractMarshaller
{
- private Stack stack = new StackImpl();
-
- /**
- * ObjectModelProvider for this marshaller
- */
- private GenericObjectModelProvider provider;
-
- private Object root;
-
- /**
- * Whether NULL values should be ignored or marshalled as xsi:nil='1'
- */
- private boolean supportNil = true;
-
- private QName rootTypeQName;
-
- private SchemaBindingResolver schemaResolver;
-
- private XSModel model;
-
- private boolean ignoreUnresolvedWildcard;
-
- private XSAttributeUse currentAttribute;
- private XSTypeDefinition currentElementType;
-
- private String simpleContentProperty = "value";//$NON-NLS-1$
-
- private MarshallingContext ctx = new MarshallingContext()
- {
- private ContentHandler ch;
-
- public boolean isAttributeRequired()
- {
- if(currentAttribute == null)
- {
- throw new JBossXBRuntimeException("There is no current
attribute!"); //$NON-NLS-1$
- }
- return currentAttribute.getRequired();
- }
-
- public boolean isTypeComplex()
- {
- if(currentElementType == null)
- {
- throw new JBossXBRuntimeException("There is no current element!");
//$NON-NLS-1$
- }
- return currentElementType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE;
- }
-
- public String getSimpleContentProperty()
- {
- return simpleContentProperty;
- }
-
- public ContentHandler getContentHandler()
- {
- if(ch == null)
- {
- ch = new ContentHandlerAdaptor();
- }
- return ch;
- }
-
- public NamespaceRegistry getNamespaceContext()
- {
- return nsRegistry;
- }
- };
-
- public String getSimpleContentProperty()
- {
- return simpleContentProperty;
- }
-
- public void setSimpleContentProperty(String simpleContentProperty)
- {
- this.simpleContentProperty = simpleContentProperty;
- }
-
- public boolean isIgnoreUnresolvedWildcard()
- {
- return ignoreUnresolvedWildcard;
- }
-
- public void setIgnoreUnresolvedWildcard(boolean ignoreUnresolvedWildcard)
- {
- this.ignoreUnresolvedWildcard = ignoreUnresolvedWildcard;
- }
-
- public SchemaBindingResolver getSchemaResolver()
- {
- return schemaResolver;
- }
-
- public void setSchemaResolver(SchemaBindingResolver schemaResolver)
- {
- this.schemaResolver = schemaResolver;
- }
-
- public QName getRootTypeQName()
- {
- return rootTypeQName;
- }
-
- public void setRootTypeQName(QName rootTypeQName)
- {
- this.rootTypeQName = rootTypeQName;
- }
-
- public boolean isSupportNil()
- {
- return supportNil;
- }
-
- public void setSupportNil(boolean supportNil)
- {
- this.supportNil = supportNil;
- }
-
- /**
- * Adds an attribute to the top most elements.
- * First, we check whether there is a namespace associated with the passed in prefix.
- * If the prefix was not declared, an exception is thrown.
- *
- * @param prefix the prefix of the attribute to be declared
- * @param localName local name of the attribute
- * @param type the type of the attribute
- * @param value the value of the attribute
- */
- public void addAttribute(String prefix, String localName, String type, String value)
- {
- // todo addAttribute(String prefix, String localName, String type, String value)
- }
-
- // AbstractMarshaller implementation
-
- public void marshal(Reader xsdReader, ObjectModelProvider provider, Object root,
Writer writer)
- throws IOException, SAXException, ParserConfigurationException
- {
- XSModel model = Util.loadSchema(xsdReader, null, schemaResolver);
- marshallInternal(provider, root, model, writer);
- }
-
- public void marshal(String xsdURL, ObjectModelProvider provider, Object root, Writer
writer) throws IOException,
- SAXException
- {
- XSModel model = Util.loadSchema(xsdURL, schemaResolver);
- marshallInternal(provider, root, model, writer);
- }
-
- public void marshal(XSModel model, ObjectModelProvider provider, Object root, Writer
writer) throws IOException,
- SAXException
- {
- marshallInternal(provider, root, model, writer);
- }
-
- private void marshallInternal(ObjectModelProvider provider, Object root, XSModel
model, Writer writer)
- throws IOException, SAXException
- {
- if(model == null)
- {
- throw new JBossXBRuntimeException("XSModel is not available!");
//$NON-NLS-1$
- }
-
- this.model = model;
- this.provider = provider instanceof GenericObjectModelProvider ?
- (GenericObjectModelProvider)provider : new
DelegatingObjectModelProvider(provider);
-
- this.root = root;
-
- content.startDocument();
-
- if(rootTypeQName != null)
- {
- if(rootQNames.isEmpty())
- {
- throw new JBossXBRuntimeException("If type name (" + //$NON-NLS-1$
- rootTypeQName +
- ") for the root element is specified then the name for the root
element is required!" //$NON-NLS-1$
- );
- }
- QName rootQName = (QName)rootQNames.get(0);
-
- XSTypeDefinition type = model.getTypeDefinition(rootTypeQName.getLocalPart(),
- rootTypeQName.getNamespaceURI()
- );
- if(type == null)
- {
- throw new JBossXBRuntimeException("Global type definition is not found:
" + rootTypeQName); //$NON-NLS-1$
- }
-
- if(isArrayWrapper(type))
- {
- Object o = provider.getRoot(root, null, rootQName.getNamespaceURI(),
rootQName.getLocalPart());
- stack.push(o);
- marshalComplexType(rootQName.getNamespaceURI(),
- rootQName.getLocalPart(),
- (XSComplexTypeDefinition)type,
- true,
- false
- );
- stack.pop();
- }
- else
- {
- Object o = provider.getRoot(root, null, rootQName.getNamespaceURI(),
rootQName.getLocalPart());
- marshalElementOccurence(rootQName.getNamespaceURI(),
- rootQName.getLocalPart(),
- type,
- o,
- false,
- false,
- true
- );
- }
- }
- else if(rootQNames.isEmpty())
- {
- XSNamedMap components = model.getComponents(XSConstants.ELEMENT_DECLARATION);
- if(components.getLength() == 0)
- {
- throw new JBossXBRuntimeException("The schema doesn't contain global
element declarations."); //$NON-NLS-1$
- }
-
- for(int i = 0; i < components.getLength(); ++i)
- {
- XSElementDeclaration element = (XSElementDeclaration)components.item(i);
- Object o = provider.getRoot(root, null, element.getNamespace(),
element.getName());
- marshalElementOccurence(element.getNamespace(),
- element.getName(),
- element.getTypeDefinition(),
- o,
- element.getNillable(),
- false,
- true
- );
- }
- }
- else
- {
- for(int i = 0; i < rootQNames.size(); ++i)
- {
- QName qName = (QName)rootQNames.get(i);
- XSElementDeclaration element =
model.getElementDeclaration(qName.getLocalPart(), qName.getNamespaceURI());
- if(element == null)
- {
- XSNamedMap components =
model.getComponents(XSConstants.ELEMENT_DECLARATION);
- String roots = ""; //$NON-NLS-1$
- for(int j = 0; j < components.getLength(); ++j)
- {
- XSObject xsObject = components.item(j);
- if(j > 0)
- {
- roots += ", "; //$NON-NLS-1$
- }
- roots += "{" + xsObject.getNamespace() + "}" +
xsObject.getName(); //$NON-NLS-1$ //$NON-NLS-2$
- }
- throw new IllegalStateException("Root element not found: " +
qName + " among " + roots); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- Object o = provider.getRoot(root, null, element.getNamespace(),
element.getName());
- marshalElementOccurence(element.getNamespace(),
- element.getName(),
- element.getTypeDefinition(),
- o,
- element.getNillable(),
- false,
- true
- );
- }
- }
-
- content.endDocument();
-
- // version & encoding
- writeXmlVersion(writer);
-
- ContentWriter contentWriter = new ContentWriter(writer,
- propertyIsTrueOrNotSet(Marshaller.PROP_OUTPUT_INDENTATION)
- );
- content.handleContent(contentWriter);
-
- if(log.isTraceEnabled())
- {
- java.io.StringWriter traceWriter = new java.io.StringWriter();
- contentWriter = new ContentWriter(traceWriter,
- propertyIsTrueOrNotSet(Marshaller.PROP_OUTPUT_INDENTATION)
- );
- content.handleContent(contentWriter);
- log.trace("marshalled:\n" + traceWriter.getBuffer().toString());
//$NON-NLS-1$
- }
- }
-
- private boolean marshalElement(String elementNs, String elementLocal,
- XSTypeDefinition type,
- boolean optional,
- boolean nillable,
- boolean declareNs,
- boolean declareXsiType)
- {
- Object value = stack.peek();
- boolean result = value != null || value == null && (optional || nillable);
- boolean trace = log.isTraceEnabled() && result;
- if(trace)
- {
- String prefix = getPrefix(elementNs);
- log.trace("started element ns=" + elementNs + ", local=" +
elementLocal + ", prefix=" + prefix); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- }
-
- if(value != null)
- {
- marshalElementType(elementNs, elementLocal, type, declareNs, nillable,
declareXsiType);
- }
- else if(nillable)
- {
- writeNillable(elementNs, elementLocal, nillable);
- }
-
- if(trace)
- {
- log.trace("finished element ns=" + elementNs + ", local=" +
elementLocal); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- return result;
- }
-
- private void marshalElementType(String elementNs,
- String elementLocal,
- XSTypeDefinition type,
- boolean declareNs,
- boolean nillable,
- boolean declareXsiType)
- {
- switch(type.getTypeCategory())
- {
- case XSTypeDefinition.SIMPLE_TYPE:
- marshalSimpleType(elementNs,
- elementLocal,
- (XSSimpleTypeDefinition)type,
- declareNs,
- nillable,
- declareXsiType
- );
- break;
- case XSTypeDefinition.COMPLEX_TYPE:
- marshalComplexType(elementNs, elementLocal, (XSComplexTypeDefinition)type,
declareNs, declareXsiType);
- break;
- default:
- throw new IllegalStateException("Unexpected type category: " +
type.getTypeCategory()); //$NON-NLS-1$
- }
- }
-
- private void marshalSimpleType(String elementUri,
- String elementLocal,
- XSSimpleTypeDefinition type,
- boolean declareNs,
- boolean nillable,
- boolean declareXsiType)
- {
- Object value = stack.peek();
- if(value != null)
- {
- String prefix = getPrefix(elementUri);
- boolean genPrefix = prefix == null && elementUri != null &&
elementUri.length() > 0;
- if(genPrefix)
- {
- prefix = "ns_" + elementLocal; //$NON-NLS-1$
- }
-
- AttributesImpl attrs = null;
- String typeName = type.getName();
- if(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
- SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
- type.getItemType() != null &&
- (SimpleTypeBindings.XS_QNAME_NAME.equals(type.getItemType().getName()) ||
- SimpleTypeBindings.XS_NOTATION_NAME.equals(type.getItemType().getName())
- )
- )
- {
- attrs = new AttributesImpl(5);
- }
-
- String marshalled = marshalCharacters(elementUri, prefix, type, value, attrs);
-
- if((declareNs || declareXsiType) && nsRegistry.size() > 0)
- {
- if(attrs == null)
- {
- attrs = new AttributesImpl(nsRegistry.size() + 1);
- }
- declareNs(attrs);
- }
-
- if(declareXsiType)
- {
- declareXsiType(type, attrs);
- }
-
- if(genPrefix)
- {
- if(attrs == null)
- {
- attrs = new AttributesImpl(1);
- }
- attrs.add(null, prefix, "xmlns:" + prefix, null,
(String)elementUri); //$NON-NLS-1$
- }
-
- String qName = prefixLocalName(prefix, elementLocal);
-
- content.startElement(elementUri, elementLocal, qName, attrs);
- content.characters(marshalled.toCharArray(), 0, marshalled.length());
- content.endElement(elementUri, elementLocal, qName);
- }
- else
- {
- writeNillable(elementUri, elementLocal, nillable);
- }
- }
-
- private void marshalComplexType(String elementNsUri,
- String elementLocalName,
- XSComplexTypeDefinition type,
- boolean declareNs,
- boolean declareXsiType)
- {
- Object o = stack.peek();
- XSParticle particle = type.getParticle();
-
- XSObjectList attributeUses = type.getAttributeUses();
- int attrsTotal = declareNs || declareXsiType ?
- nsRegistry.size() + attributeUses.getLength() + 1 :
- attributeUses.getLength();
- AttributesImpl attrs = attrsTotal > 0 ? new AttributesImpl(attrsTotal) : null;
-
- if(declareNs && nsRegistry.size() > 0)
- {
- declareNs(attrs);
- }
-
- String generatedPrefix = null;
- if(declareXsiType)
- {
- generatedPrefix = declareXsiType(type, attrs);
- if(generatedPrefix != null)
- {
- String typeNsWithGeneratedPrefix = type.getNamespace();
- declareNs(attrs, generatedPrefix, typeNsWithGeneratedPrefix);
- declareNamespace(generatedPrefix, typeNsWithGeneratedPrefix);
- }
- }
-
- String prefix = getPrefix(elementNsUri);
- boolean genPrefix = prefix == null && elementNsUri != null &&
elementNsUri.length() > 0;
- if(genPrefix)
- {
- // todo: it's possible that the generated prefix already mapped. this should
be fixed
- prefix = "ns_" + elementLocalName; //$NON-NLS-1$
- declareNamespace(prefix, elementNsUri);
- if(attrs == null)
- {
- attrs = new AttributesImpl(1);
- }
- attrs.add(null, prefix, "xmlns:" + prefix, null, elementNsUri);
//$NON-NLS-1$
- }
-
- for(int i = 0; i < attributeUses.getLength(); ++i)
- {
- currentAttribute = (XSAttributeUse)attributeUses.item(i);
- XSAttributeDeclaration attrDec = currentAttribute.getAttrDeclaration();
- String attrNs = attrDec.getNamespace();
- String attrLocal = attrDec.getName();
- Object attrValue = provider.getAttributeValue(o, ctx, attrNs, attrLocal);
-
- if(attrValue != null)
- {
- if(attrs == null)
- {
- attrs = new AttributesImpl(5);
- }
-
- String attrPrefix = null;
- if(attrNs != null)
- {
- attrPrefix = getPrefix(attrNs);
- if(attrPrefix == null && attrNs != null && attrNs.length()
> 0)
- {
- attrPrefix = "ns_" + attrLocal; //$NON-NLS-1$
- attrs.add(null, attrPrefix, "xmlns:" + attrPrefix, null,
attrNs); //$NON-NLS-1$
- }
- }
-
- String qName = attrPrefix == null || attrPrefix.length() == 0 ? attrLocal :
attrPrefix + ":" + attrLocal; //$NON-NLS-1$
-
- // todo: this is a quick fix for boolean pattern (0|1 or true|false) should
be refactored
- XSSimpleTypeDefinition attrType = attrDec.getTypeDefinition();
- if(attrType.getItemType() != null)
- {
- XSSimpleTypeDefinition itemType = attrType.getItemType();
- if(Constants.NS_XML_SCHEMA.equals(itemType.getNamespace()))
- {
- List list;
- if(attrValue instanceof List)
- {
- list = (List)attrValue;
- }
- else if(attrValue.getClass().isArray())
- {
- list = Arrays.asList((Object[])attrValue);
- }
- else
- {
- throw new JBossXBRuntimeException("Expected value for list type
is an array or " + //$NON-NLS-1$
- List.class.getName() +
- " but got: " + //$NON-NLS-1$
- attrValue
- );
- }
-
- if(Constants.QNAME_QNAME.getLocalPart().equals(itemType.getName()))
- {
- for(int listInd = 0; listInd < list.size(); ++listInd)
- {
- QName item = (QName)list.get(listInd);
- String itemNs = item.getNamespaceURI();
- if(itemNs != null && itemNs.length() > 0)
- {
- String itemPrefix;
- if(itemNs.equals(elementNsUri))
- {
- itemPrefix = prefix;
- }
- else
- {
- itemPrefix = getPrefix(itemNs);
- if(itemPrefix == null)
- {
- itemPrefix = attrLocal + listInd;
- declareNs(attrs, itemPrefix, itemNs);
- }
- }
- item = new QName(item.getNamespaceURI(), item.getLocalPart(),
itemPrefix);
- list.set(listInd, item);
- }
- }
- }
-
- attrValue = SimpleTypeBindings.marshalList(itemType.getName(), list,
null);
- }
- else
- {
- throw new JBossXBRuntimeException("Marshalling of list types with
item types not from " + //$NON-NLS-1$
- Constants.NS_XML_SCHEMA + " is not supported."
//$NON-NLS-1$
- );
- }
- }
- else if(attrType.getLexicalPattern().item(0) != null
- &&
- attrType.derivedFrom(Constants.NS_XML_SCHEMA,
- Constants.QNAME_BOOLEAN.getLocalPart(),
- XSConstants.DERIVATION_RESTRICTION
- ))
- {
- String item = attrType.getLexicalPattern().item(0);
- if(item.indexOf('0') != -1 && item.indexOf('1') !=
-1)
- {
- attrValue = ((Boolean)attrValue).booleanValue() ? "1" :
"0"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- else
- {
- attrValue = ((Boolean)attrValue).booleanValue() ? "true" :
"false"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- else
if(Constants.QNAME_QNAME.getNamespaceURI().equals(attrType.getNamespace()) &&
- Constants.QNAME_QNAME.getLocalPart().equals(attrType.getName()))
- {
- QName qNameValue = (QName)attrValue;
-
- String qNamePrefix = null;
- boolean declarePrefix = false;
- String ns = qNameValue.getNamespaceURI();
- if(ns != null && ns.length() > 0)
- {
- qNamePrefix = getPrefix(ns);
- if(qNamePrefix == null)
- {
- qNamePrefix = qNameValue.getPrefix();
- if(qNamePrefix == null || qNamePrefix.length() == 0)
- {
- qNamePrefix = "ns_" + qNameValue.getLocalPart();
//$NON-NLS-1$
- }
- declareNs(attrs, qNamePrefix, ns);
- nsRegistry.addPrefixMapping(qNamePrefix, ns);
- declarePrefix = true;
- }
- }
-
- attrValue = SimpleTypeBindings.marshalQName(qNameValue, nsRegistry);
-
- if(declarePrefix)
- {
- nsRegistry.removePrefixMapping(qNamePrefix);
- }
- }
- else
- {
- attrValue = attrValue.toString();
- }
-
- attrs.add(attrNs,
- attrLocal,
- qName,
- attrDec.getTypeDefinition().getName(),
- attrValue.toString()
- );
- } // end if attrValue != null
- else if( currentAttribute.getRequired()){
- // its required and is not present. Must throw exception
- String name = currentAttribute.getAttrDeclaration().getName();
- throw new JBossXBRuntimeException("Required Attribute " + name +
" is not present"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- currentAttribute = null;
-
- String characters = null;
- if(type.getSimpleType() != null)
- {
- Object value = getSimpleContentValue(elementNsUri, elementLocalName, type);
- if(value != null)
- {
- XSSimpleTypeDefinition simpleType = type.getSimpleType();
- String typeName = simpleType.getName();
- if(attrs == null &&
(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
- SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
- simpleType.getItemType() != null &&
-
(SimpleTypeBindings.XS_QNAME_NAME.equals(simpleType.getItemType().getName()) ||
-
SimpleTypeBindings.XS_NOTATION_NAME.equals(simpleType.getItemType().getName())
- )
- )
- )
- {
- attrs = new AttributesImpl(5);
- }
-
- characters = marshalCharacters(elementNsUri, prefix, simpleType, value,
attrs);
- }
- }
-
- String qName = prefixLocalName(prefix, elementLocalName);
- content.startElement(elementNsUri, elementLocalName, qName, attrs);
-
- if(particle != null)
- {
- marshalParticle(particle, false);
- }
-
- if(characters != null)
- {
- content.characters(characters.toCharArray(), 0, characters.length());
- }
- content.endElement(elementNsUri, elementLocalName, qName);
-
- if(genPrefix)
- {
- removePrefixMapping(prefix);
- }
-
- if(generatedPrefix != null)
- {
- removePrefixMapping(generatedPrefix);
- }
- }
-
- private boolean marshalParticle(XSParticle particle, boolean declareNs)
- {
- boolean marshalled;
- XSTerm term = particle.getTerm();
- Object o;
- Iterator i;
- switch(term.getType())
- {
- case XSConstants.MODEL_GROUP:
- o = stack.peek();
- i = o != null && isRepeatable(particle) ? getIterator(o) : null;
- if(i != null)
- {
- marshalled = true;
- while(i.hasNext() && marshalled)
- {
- Object value = i.next();
- stack.push(value);
- marshalled = marshalModelGroup(particle, declareNs);
- stack.pop();
- }
- }
- else
- {
- marshalled = marshalModelGroup(particle, declareNs);
- }
- break;
- case XSConstants.WILDCARD:
- o = stack.peek();
-
- boolean popWildcardValue = false;
- ObjectLocalMarshaller marshaller = null;
- FieldToWildcardMapping mapping =
(FieldToWildcardMapping)field2WildcardMap.get(o.getClass());
- if(mapping != null)
- {
- marshaller = mapping.marshaller;
- o = mapping.fieldInfo.getValue(o);
- stack.push(o);
- popWildcardValue = true;
- }
-
- i = o != null && isRepeatable(particle) ? getIterator(o) : null;
- if(i != null)
- {
- marshalled = true;
- while(i.hasNext() && marshalled)
- {
- Object value = i.next();
- marshalled = marshalWildcardOccurence(particle, marshaller, value,
declareNs);
- }
- }
- else
- {
- marshalled = marshalWildcardOccurence(particle, marshaller, o,
declareNs);
- }
-
- if(popWildcardValue)
- {
- stack.pop();
- }
-
- break;
- case XSConstants.ELEMENT_DECLARATION:
- XSElementDeclaration element = (XSElementDeclaration)term;
- XSTypeDefinition type = element.getTypeDefinition();
- o = getElementValue(element.getNamespace(), element.getName(), type);
-
- i = o != null && isRepeatable(particle) ? getIterator(o) : null;
- if(i != null)
- {
- marshalled = true;
- while(i.hasNext() && marshalled)
- {
- Object value = i.next();
- marshalled =
- marshalElementOccurence(element.getNamespace(),
- element.getName(),
- type,
- value,
- element.getNillable(),
- particle.getMinOccurs() == 0,
- declareNs
- );
- }
- }
- else
- {
- marshalled =
- marshalElementOccurence(element.getNamespace(),
- element.getName(),
- type,
- o,
- element.getNillable(),
- particle.getMinOccurs() == 0,
- declareNs
- );
- }
- break;
- default:
- throw new IllegalStateException("Unexpected term type: " +
term.getType()); //$NON-NLS-1$
- }
- return marshalled;
- }
-
- private boolean marshalElementOccurence(String elementNs,
- String elementLocal,
- XSTypeDefinition type,
- Object value,
- boolean nillable,
- boolean optional,
- boolean declareNs)
- {
- boolean declareXsiType = false;
- QName xsiTypeQName = null;
- if(value != null)
- {
- xsiTypeQName = (QName)cls2TypeMap.get(value.getClass());
- if(xsiTypeQName != null &&
- !(type.getName().equals(xsiTypeQName.getLocalPart()) &&
- type.getNamespace().equals(xsiTypeQName.getNamespaceURI())
- ))
- {
- declareXsiType = true;
- if(log.isTraceEnabled())
- {
- log.trace(value.getClass() + " is mapped to xsi:type " +
xsiTypeQName); //$NON-NLS-1$
- }
-
- XSTypeDefinition xsiType =
model.getTypeDefinition(xsiTypeQName.getLocalPart(),
- xsiTypeQName.getNamespaceURI()
- );
-
- if(xsiType == null)
- {
- log.warn("Class " + //$NON-NLS-1$
- value.getClass() +
- " is mapped to type " + //$NON-NLS-1$
- xsiTypeQName +
- " but the type is not found in schema." //$NON-NLS-1$
- );
- }
- // todo should check derivation also, i.e. if(xsiType.derivedFrom())
- else
- {
- type = xsiType;
- }
- }
- }
-
- stack.push(value);
- boolean marshalled = marshalElement(elementNs,
- elementLocal,
- type,
- optional,
- nillable,
- declareNs,
- declareXsiType
- );
- stack.pop();
-
- return marshalled;
- }
-
- private boolean marshalWildcardOccurence(XSParticle particle,
- ObjectLocalMarshaller marshaller,
- Object value,
- boolean declareNs)
- {
- boolean marshalled = true;
- if(marshaller != null)
- {
- marshaller.marshal(ctx, value);
- }
- else
- {
- stack.push(value);
- marshalled = marshalWildcard(particle, declareNs);
- stack.pop();
- }
- return marshalled;
- }
-
- private boolean marshalWildcard(XSParticle particle, boolean declareNs)
- {
- XSWildcard wildcard = (XSWildcard)particle.getTerm();
- Object o = stack.peek();
- ClassMapping mapping = getClassMapping(o.getClass());
- if(mapping == null)
- {
- // todo: YAH (yet another hack)
- QName autoType = SimpleTypeBindings.typeQName(o.getClass());
- if(autoType != null)
- {
- String marshalled = SimpleTypeBindings.marshal(autoType.getLocalPart(), o,
null);
- content.characters(marshalled.toCharArray(), 0, marshalled.length());
- return true;
- }
- else
- {
- if(ignoreUnresolvedWildcard)
- {
- log.warn("Failed to marshal wildcard. Class mapping not found for
" + //$NON-NLS-1$
- o.getClass() +
- "@" + //$NON-NLS-1$
- o.hashCode() +
- ": " + o //$NON-NLS-1$
- );
- return true;
- }
- else
- {
- throw new IllegalStateException("Failed to marshal wildcard. Class
mapping not found for " + //$NON-NLS-1$
- o.getClass() +
- "@" + //$NON-NLS-1$
- o.hashCode() +
- ": " + o //$NON-NLS-1$
- );
- }
- }
- }
-
- GenericObjectModelProvider parentProvider = this.provider;
- Object parentRoot = this.root;
- Stack parentStack = this.stack;
- XSModel parentModel = this.model;
-
- this.root = o;
- this.stack = new StackImpl();
- this.model = mapping.schemaUrl == null ? this.model :
Util.loadSchema(mapping.schemaUrl, schemaResolver);
- if(mapping.provider != null)
- {
- this.provider = mapping.provider;
- }
-
- boolean marshalled;
- if(mapping.elementName != null)
- {
- XSElementDeclaration elDec =
model.getElementDeclaration(mapping.elementName.getLocalPart(),
- mapping.elementName.getNamespaceURI()
- );
-
- if(elDec == null)
- {
- throw new JBossXBRuntimeException("Element " + mapping.elementName
+ " is not declared in the schema."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- Object elementValue = provider.getRoot(root, null, elDec.getNamespace(),
elDec.getName());
- marshalled = marshalElementOccurence(elDec.getNamespace(),
- elDec.getName(),
- elDec.getTypeDefinition(),
- elementValue,
- elDec.getNillable(),
- particle.getMinOccurs() == 0,
- declareNs
- );
- }
- else if(mapping.typeName != null)
- {
- XSTypeDefinition typeDef =
model.getTypeDefinition(mapping.typeName.getLocalPart(),
- mapping.typeName.getNamespaceURI()
- );
-
- if(typeDef == null)
- {
- List typeNames = new ArrayList();
- XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
- for(int i = 0; i < types.getLength(); ++i)
- {
- XSObject type = types.item(i);
- if(!Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
- {
- typeNames.add(new QName(type.getNamespace(), type.getName()));
- }
- }
- throw new JBossXBRuntimeException("Type " + //$NON-NLS-1$
- mapping.typeName +
- " is not defined in the schema." + //$NON-NLS-1$
- " Defined types are: " + typeNames //$NON-NLS-1$
- );
- }
-
- Object elementValue = provider.getRoot(root, null, wildcard.getNamespace(),
wildcard.getName());
- marshalled =
- marshalElementOccurence(wildcard.getNamespace(),
- wildcard.getName(),
- typeDef,
- elementValue,
- true,
- particle.getMinOccurs() == 0,
- declareNs
- );
- }
- else
- {
- throw new JBossXBRuntimeException("Class mapping for " +
//$NON-NLS-1$
- mapping.cls +
- " is associated with neither global element name nor global type
name." //$NON-NLS-1$
- );
- }
-
- this.root = parentRoot;
- this.provider = parentProvider;
- this.stack = parentStack;
- this.model = parentModel;
-
- return marshalled;
- }
-
- private boolean marshalModelGroup(XSParticle particle, boolean declareNs)
- {
- XSModelGroup modelGroup = (XSModelGroup)particle.getTerm();
- boolean marshalled;
- switch(modelGroup.getCompositor())
- {
- case XSModelGroup.COMPOSITOR_ALL:
- marshalled = marshalModelGroupAll(modelGroup.getParticles(), declareNs);
- break;
- case XSModelGroup.COMPOSITOR_CHOICE:
- marshalled = marshalModelGroupChoice(modelGroup.getParticles(), declareNs);
- break;
- case XSModelGroup.COMPOSITOR_SEQUENCE:
- marshalled = marshalModelGroupSequence(modelGroup.getParticles(),
declareNs);
- break;
- default:
- throw new IllegalStateException("Unexpected compsitor: " +
modelGroup.getCompositor()); //$NON-NLS-1$
- }
- return marshalled;
- }
-
- private boolean marshalModelGroupAll(XSObjectList particles, boolean declareNs)
- {
- boolean marshalled = false;
- for(int i = 0; i < particles.getLength(); ++i)
- {
- XSParticle particle = (XSParticle)particles.item(i);
- marshalled |= marshalParticle(particle, declareNs);
- }
- return marshalled;
- }
-
- private boolean marshalModelGroupChoice(XSObjectList particles, boolean declareNs)
- {
- boolean marshalled = false;
- Content mainContent = this.content;
- for(int i = 0; i < particles.getLength() && !marshalled; ++i)
- {
- XSParticle particle = (XSParticle)particles.item(i);
- this.content = new Content();
- marshalled = marshalParticle(particle, declareNs);
- }
-
- if(marshalled)
- {
- mainContent.append(this.content);
- }
- this.content = mainContent;
-
- return marshalled;
- }
-
- private boolean marshalModelGroupSequence(XSObjectList particles, boolean declareNs)
- {
- boolean marshalled = true;
- for(int i = 0; i < particles.getLength(); ++i)
- {
- XSParticle particle = (XSParticle)particles.item(i);
- marshalled &= marshalParticle(particle, declareNs);
- }
- return marshalled;
- }
-
- private String marshalCharacters(String elementUri,
- String elementPrefix,
- XSSimpleTypeDefinition type,
- Object value,
- AttributesImpl attrs)
- {
- String marshalled;
- if(type.getItemType() != null)
- {
- XSSimpleTypeDefinition itemType = type.getItemType();
- if(Constants.NS_XML_SCHEMA.equals(itemType.getNamespace()))
- {
- List list;
- if(value instanceof List)
- {
- list = (List)value;
- }
- else if(value.getClass().isArray())
- {
- list = asList(value);
- }
- else
- {
- // todo: qname are also not yet supported
- throw new JBossXBRuntimeException(
- "Expected value for list type is an array or " +
List.class.getName() + " but got: " + value //$NON-NLS-1$ //$NON-NLS-2$
- );
- }
-
- marshalled = SimpleTypeBindings.marshalList(itemType.getName(), list, null);
- }
- else
- {
- throw new JBossXBRuntimeException("Marshalling of list types with item
types not from " + //$NON-NLS-1$
- Constants.NS_XML_SCHEMA + " is not supported." //$NON-NLS-1$
- );
- }
- }
- else if(Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
- {
- String typeName = type.getName();
-
- String prefix = null;
- boolean removePrefix = false;
- if(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
- SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName))
- {
- QName qName = (QName)value;
- if(qName.getNamespaceURI() != null &&
qName.getNamespaceURI().length() > 0)
- {
- prefix = nsRegistry.getPrefix(qName.getNamespaceURI());
- if(prefix == null)
- {
- prefix = qName.getPrefix();
- if(prefix == null || prefix.length() == 0)
- {
- prefix = qName.getLocalPart() + "_ns"; //$NON-NLS-1$
- }
- nsRegistry.addPrefixMapping(prefix, qName.getNamespaceURI());
- declareNs(attrs, prefix, qName.getNamespaceURI());
-
- removePrefix = true;
- }
- }
- }
- marshalled = SimpleTypeBindings.marshal(typeName, value, nsRegistry);
-
- if(removePrefix)
- {
- nsRegistry.removePrefixMapping(prefix);
- }
- }
- // todo: this is a quick fix for boolean pattern (0|1 or true|false) should be
refactored
- else if(type.getLexicalPattern().item(0) != null
- &&
- type.derivedFrom(Constants.NS_XML_SCHEMA,
- Constants.QNAME_BOOLEAN.getLocalPart(),
- XSConstants.DERIVATION_RESTRICTION
- ))
- {
- String item = type.getLexicalPattern().item(0);
- if(item.indexOf('0') != -1 && item.indexOf('1') != -1)
- {
- marshalled = ((Boolean)value).booleanValue() ? "1" :
"0";//$NON-NLS-1$ //$NON-NLS-2$
- }
- else
- {
- marshalled = ((Boolean)value).booleanValue() ? "true" :
"false";//$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- else
- {
- StringList lexicalEnumeration = type.getLexicalEnumeration();
- if(lexicalEnumeration != null && lexicalEnumeration.getLength() > 0)
- {
- Method getValue;
- try
- {
- getValue = value.getClass().getMethod("value", null);
//$NON-NLS-1$
- }
- catch(NoSuchMethodException e)
- {
- try
- {
- getValue = value.getClass().getMethod("getValue", null);
//$NON-NLS-1$
- }
- catch(NoSuchMethodException e1)
- {
- List values = new ArrayList(lexicalEnumeration.getLength());
- for(int i = 0; i < lexicalEnumeration.getLength(); ++i)
- {
- values.add(lexicalEnumeration.item(i));
- }
-
- throw new JBossXBRuntimeException("Failed to find neither value()
nor getValue() in " + //$NON-NLS-1$
- value.getClass() +
- " which is bound to enumeration type (" + //$NON-NLS-1$
- type.getNamespace() +
- ", " + //$NON-NLS-1$
- type.getName() + "): " + values //$NON-NLS-1$
- );
- }
- }
-
- try
- {
- value = getValue.invoke(value, null);
- }
- catch(Exception e)
- {
- throw new JBossXBRuntimeException(
- "Failed to invoke getValue() on " + value + " to get the
enumeration value", e//$NON-NLS-1$ //$NON-NLS-2$
- );
- }
- }
-
- marshalled = marshalCharacters(elementUri,
- elementPrefix,
- (XSSimpleTypeDefinition)type.getBaseType(),
- value, attrs
- );
- }
- return marshalled;
- }
-
- /**
- * Adds xsi:type attribute and optionally declares namespaces for xsi and type's
namespace.
- * @param type the type to declare xsi:type attribute for
- * @param attrs the attributes to add xsi:type attribute to
- * @return prefix for the type's ns if it was generated
- */
- private String declareXsiType(XSTypeDefinition type, AttributesImpl attrs)
- {
- String result = null;
- String xsiPrefix = nsRegistry.getPrefix(Constants.NS_XML_SCHEMA_INSTANCE);
- if(xsiPrefix == null)
- {
- attrs.add(Constants.NS_XML_SCHEMA, "xmlns", "xmlns:xsi",
null, Constants.NS_XML_SCHEMA_INSTANCE);//$NON-NLS-1$ //$NON-NLS-2$
- xsiPrefix = "xsi"; //$NON-NLS-1$
- }
-
- String pref = getPrefix(type.getNamespace());
- if(pref == null)
- {
- // the ns is not declared
- result = pref = type.getName() + "_ns"; //$NON-NLS-1$
- }
-
- String typeQName = pref == null ? type.getName() : pref + ':' +
type.getName();
- attrs.add(Constants.NS_XML_SCHEMA_INSTANCE, "type", xsiPrefix +
":type", null, typeQName);//$NON-NLS-1$ //$NON-NLS-2$
- return result;
- }
-
- private Object getElementValue(String elementNs, String elementLocal, XSTypeDefinition
type)
- {
- Object value;
- Object peeked = stack.isEmpty() ? root : stack.peek();
- if(peeked == null)
- {
- value = null;
- }
- else if(peeked instanceof Collection || peeked.getClass().isArray())
- {
- // collection is the provider
- value = peeked;
- }
- else
- {
- XSTypeDefinition parentType = currentElementType;
- currentElementType = type;
-
- value = provider.getChildren(peeked, ctx, elementNs, elementLocal);
- if(value == null)
- {
- value = provider.getElementValue(peeked, ctx, elementNs, elementLocal);
- }
-
- currentElementType = parentType;
- }
- return value;
- }
-
- private Object getSimpleContentValue(String elementNs, String elementLocal,
XSTypeDefinition type)
- {
- Object value;
- Object peeked = stack.isEmpty() ? root : stack.peek();
- if(peeked == null)
- {
- value = null;
- }
- else
- {
- XSTypeDefinition parentType = currentElementType;
- currentElementType = type;
- value = provider.getElementValue(peeked, ctx, elementNs, elementLocal);
- currentElementType = parentType;
- }
- return value;
- }
-
- private void writeNillable(String elementNs, String elementLocal, boolean nillable)
- {
- if(!supportNil)
- {
- return;
- }
-
- if(!nillable)
- {
- throw new JBossXBRuntimeException("Failed to marshal " +
//$NON-NLS-1$
- new QName(elementNs, elementLocal) +
- ": Java value is null but the element is not nillable."
//$NON-NLS-1$
- );
- }
-
- AttributesImpl attrs;
- String prefix = getPrefix(elementNs);
- if(prefix == null && elementNs != null && elementNs.length() >
0)
- {
- prefix = "ns_" + elementLocal; //$NON-NLS-1$
- attrs = new AttributesImpl(2);
- attrs.add(null, prefix, "xmlns:" + prefix, null, elementNs);
//$NON-NLS-1$
- }
- else
- {
- attrs = new AttributesImpl(1);
- }
-
- String xsiPrefix = getPrefix(Constants.NS_XML_SCHEMA_INSTANCE);
- if(xsiPrefix == null)
- {
- xsiPrefix = "xsi"; //$NON-NLS-1$
- attrs.add(null,
- xsiPrefix,
- "xmlns:xsi", //$NON-NLS-1$
- null,
- Constants.NS_XML_SCHEMA_INSTANCE
- );
- }
-
- String nilQName = xsiPrefix + ":nil"; //$NON-NLS-1$
- attrs.add(Constants.NS_XML_SCHEMA_INSTANCE, "nil", nilQName, null,
"1"); //$NON-NLS-1$ //$NON-NLS-2$
-
- String qName = prefixLocalName(prefix, elementLocal);
- content.startElement(elementNs, elementLocal, qName, attrs);
- content.endElement(elementNs, elementLocal, qName);
- }
-
- private static boolean isArrayWrapper(XSTypeDefinition type)
- {
- boolean is = false;
- if(XSTypeDefinition.COMPLEX_TYPE == type.getTypeCategory())
- {
- XSComplexTypeDefinition cType = (XSComplexTypeDefinition)type;
- XSParticle particle = cType.getParticle();
- if(particle != null)
- {
- is = particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1;
- }
- }
- return is;
- }
-
- private Iterator getIterator(Object value)
- {
- Iterator i = null;
- if(value instanceof Collection)
- {
- i = ((Collection)value).iterator();
- }
- else if(value.getClass().isArray())
- {
- final Object arr = value;
- i = new Iterator()
- {
- private int curInd = 0;
- private int length = Array.getLength(arr);
-
- public boolean hasNext()
- {
- return curInd < length;
- }
-
- public Object next()
- {
- return Array.get(arr, curInd++);
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException("remove is not
implemented."); //$NON-NLS-1$
- }
- };
- }
- else if(value instanceof Iterator)
- {
- i = (Iterator)value;
- }
- else
- {
- //throw new JBossXBRuntimeException("Unexpected type for children: " +
value.getClass());
- }
- return i;
- }
-
- private static boolean isRepeatable(XSParticle particle)
- {
- return particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1 ||
particle.getMinOccurs() > 1;
- }
-
- private static final List asList(final Object arr)
- {
- return new AbstractList()
- {
- private final Object array = arr;
-
- public Object get(int index)
- {
- return Array.get(array, index);
- }
-
- public int size()
- {
- return Array.getLength(array);
- }
- };
- }
+// private Stack stack = new StackImpl();
+//
+// /**
+// * ObjectModelProvider for this marshaller
+// */
+// private GenericObjectModelProvider provider;
+//
+// private Object root;
+//
+// /**
+// * Whether NULL values should be ignored or marshalled as xsi:nil='1'
+// */
+// private boolean supportNil = true;
+//
+// private QName rootTypeQName;
+//
+// private SchemaBindingResolver schemaResolver;
+//
+// private XSModel model;
+//
+// private boolean ignoreUnresolvedWildcard;
+//
+// private XSAttributeUse currentAttribute;
+// private XSTypeDefinition currentElementType;
+//
+// private String simpleContentProperty = "value";//$NON-NLS-1$
+//
+// private MarshallingContext ctx = new MarshallingContext()
+// {
+// private ContentHandler ch;
+//
+// public boolean isAttributeRequired()
+// {
+// if(currentAttribute == null)
+// {
+// throw new JBossXBRuntimeException("There is no current
attribute!"); //$NON-NLS-1$
+// }
+// return currentAttribute.getRequired();
+// }
+//
+// public boolean isTypeComplex()
+// {
+// if(currentElementType == null)
+// {
+// throw new JBossXBRuntimeException("There is no current
element!"); //$NON-NLS-1$
+// }
+// return currentElementType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE;
+// }
+//
+// public String getSimpleContentProperty()
+// {
+// return simpleContentProperty;
+// }
+//
+// public ContentHandler getContentHandler()
+// {
+// if(ch == null)
+// {
+// ch = new ContentHandlerAdaptor();
+// }
+// return ch;
+// }
+//
+// public NamespaceRegistry getNamespaceContext()
+// {
+// return nsRegistry;
+// }
+// };
+//
+// public String getSimpleContentProperty()
+// {
+// return simpleContentProperty;
+// }
+//
+// public void setSimpleContentProperty(String simpleContentProperty)
+// {
+// this.simpleContentProperty = simpleContentProperty;
+// }
+//
+// public boolean isIgnoreUnresolvedWildcard()
+// {
+// return ignoreUnresolvedWildcard;
+// }
+//
+// public void setIgnoreUnresolvedWildcard(boolean ignoreUnresolvedWildcard)
+// {
+// this.ignoreUnresolvedWildcard = ignoreUnresolvedWildcard;
+// }
+//
+// public SchemaBindingResolver getSchemaResolver()
+// {
+// return schemaResolver;
+// }
+//
+// public void setSchemaResolver(SchemaBindingResolver schemaResolver)
+// {
+// this.schemaResolver = schemaResolver;
+// }
+//
+// public QName getRootTypeQName()
+// {
+// return rootTypeQName;
+// }
+//
+// public void setRootTypeQName(QName rootTypeQName)
+// {
+// this.rootTypeQName = rootTypeQName;
+// }
+//
+// public boolean isSupportNil()
+// {
+// return supportNil;
+// }
+//
+// public void setSupportNil(boolean supportNil)
+// {
+// this.supportNil = supportNil;
+// }
+//
+// /**
+// * Adds an attribute to the top most elements.
+// * First, we check whether there is a namespace associated with the passed in
prefix.
+// * If the prefix was not declared, an exception is thrown.
+// *
+// * @param prefix the prefix of the attribute to be declared
+// * @param localName local name of the attribute
+// * @param type the type of the attribute
+// * @param value the value of the attribute
+// */
+// public void addAttribute(String prefix, String localName, String type, String
value)
+// {
+// // todo addAttribute(String prefix, String localName, String type, String value)
+// }
+//
+// // AbstractMarshaller implementation
+//
+// public void marshal(Reader xsdReader, ObjectModelProvider provider, Object root,
Writer writer)
+// throws IOException, SAXException, ParserConfigurationException
+// {
+// XSModel model = Util.loadSchema(xsdReader, null, schemaResolver);
+// marshallInternal(provider, root, model, writer);
+// }
+//
+// public void marshal(String xsdURL, ObjectModelProvider provider, Object root, Writer
writer) throws IOException,
+// SAXException
+// {
+// XSModel model = Util.loadSchema(xsdURL, schemaResolver);
+// marshallInternal(provider, root, model, writer);
+// }
+//
+// public void marshal(XSModel model, ObjectModelProvider provider, Object root, Writer
writer) throws IOException,
+// SAXException
+// {
+// marshallInternal(provider, root, model, writer);
+// }
+//
+// private void marshallInternal(ObjectModelProvider provider, Object root, XSModel
model, Writer writer)
+// throws IOException, SAXException
+// {
+// if(model == null)
+// {
+// throw new JBossXBRuntimeException("XSModel is not available!");
//$NON-NLS-1$
+// }
+//
+// this.model = model;
+// this.provider = provider instanceof GenericObjectModelProvider ?
+// (GenericObjectModelProvider)provider : new
DelegatingObjectModelProvider(provider);
+//
+// this.root = root;
+//
+// content.startDocument();
+//
+// if(rootTypeQName != null)
+// {
+// if(rootQNames.isEmpty())
+// {
+// throw new JBossXBRuntimeException("If type name (" +
//$NON-NLS-1$
+// rootTypeQName +
+// ") for the root element is specified then the name for the root
element is required!" //$NON-NLS-1$
+// );
+// }
+// QName rootQName = (QName)rootQNames.get(0);
+//
+// XSTypeDefinition type = model.getTypeDefinition(rootTypeQName.getLocalPart(),
+// rootTypeQName.getNamespaceURI()
+// );
+// if(type == null)
+// {
+// throw new JBossXBRuntimeException("Global type definition is not
found: " + rootTypeQName); //$NON-NLS-1$
+// }
+//
+// if(isArrayWrapper(type))
+// {
+// Object o = provider.getRoot(root, null, rootQName.getNamespaceURI(),
rootQName.getLocalPart());
+// stack.push(o);
+// marshalComplexType(rootQName.getNamespaceURI(),
+// rootQName.getLocalPart(),
+// (XSComplexTypeDefinition)type,
+// true,
+// false
+// );
+// stack.pop();
+// }
+// else
+// {
+// Object o = provider.getRoot(root, null, rootQName.getNamespaceURI(),
rootQName.getLocalPart());
+// marshalElementOccurence(rootQName.getNamespaceURI(),
+// rootQName.getLocalPart(),
+// type,
+// o,
+// false,
+// false,
+// true
+// );
+// }
+// }
+// else if(rootQNames.isEmpty())
+// {
+// XSNamedMap components = model.getComponents(XSConstants.ELEMENT_DECLARATION);
+// if(components.getLength() == 0)
+// {
+// throw new JBossXBRuntimeException("The schema doesn't contain
global element declarations."); //$NON-NLS-1$
+// }
+//
+// for(int i = 0; i < components.getLength(); ++i)
+// {
+// XSElementDeclaration element = (XSElementDeclaration)components.item(i);
+// Object o = provider.getRoot(root, null, element.getNamespace(),
element.getName());
+// marshalElementOccurence(element.getNamespace(),
+// element.getName(),
+// element.getTypeDefinition(),
+// o,
+// element.getNillable(),
+// false,
+// true
+// );
+// }
+// }
+// else
+// {
+// for(int i = 0; i < rootQNames.size(); ++i)
+// {
+// QName qName = (QName)rootQNames.get(i);
+// XSElementDeclaration element =
model.getElementDeclaration(qName.getLocalPart(), qName.getNamespaceURI());
+// if(element == null)
+// {
+// XSNamedMap components =
model.getComponents(XSConstants.ELEMENT_DECLARATION);
+// String roots = ""; //$NON-NLS-1$
+// for(int j = 0; j < components.getLength(); ++j)
+// {
+// XSObject xsObject = components.item(j);
+// if(j > 0)
+// {
+// roots += ", "; //$NON-NLS-1$
+// }
+// roots += "{" + xsObject.getNamespace() + "}" +
xsObject.getName(); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// throw new IllegalStateException("Root element not found: " +
qName + " among " + roots); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+//
+// Object o = provider.getRoot(root, null, element.getNamespace(),
element.getName());
+// marshalElementOccurence(element.getNamespace(),
+// element.getName(),
+// element.getTypeDefinition(),
+// o,
+// element.getNillable(),
+// false,
+// true
+// );
+// }
+// }
+//
+// content.endDocument();
+//
+// // version & encoding
+// writeXmlVersion(writer);
+//
+// ContentWriter contentWriter = new ContentWriter(writer,
+// propertyIsTrueOrNotSet(Marshaller.PROP_OUTPUT_INDENTATION)
+// );
+// content.handleContent(contentWriter);
+//
+// if(log.isTraceEnabled())
+// {
+// java.io.StringWriter traceWriter = new java.io.StringWriter();
+// contentWriter = new ContentWriter(traceWriter,
+// propertyIsTrueOrNotSet(Marshaller.PROP_OUTPUT_INDENTATION)
+// );
+// content.handleContent(contentWriter);
+// log.trace("marshalled:\n" + traceWriter.getBuffer().toString());
//$NON-NLS-1$
+// }
+// }
+//
+// private boolean marshalElement(String elementNs, String elementLocal,
+// XSTypeDefinition type,
+// boolean optional,
+// boolean nillable,
+// boolean declareNs,
+// boolean declareXsiType)
+// {
+// Object value = stack.peek();
+// boolean result = value != null || value == null && (optional ||
nillable);
+// boolean trace = log.isTraceEnabled() && result;
+// if(trace)
+// {
+// String prefix = getPrefix(elementNs);
+// log.trace("started element ns=" + elementNs + ", local=" +
elementLocal + ", prefix=" + prefix); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+// }
+//
+// if(value != null)
+// {
+// marshalElementType(elementNs, elementLocal, type, declareNs, nillable,
declareXsiType);
+// }
+// else if(nillable)
+// {
+// writeNillable(elementNs, elementLocal, nillable);
+// }
+//
+// if(trace)
+// {
+// log.trace("finished element ns=" + elementNs + ", local="
+ elementLocal); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+//
+// return result;
+// }
+//
+// private void marshalElementType(String elementNs,
+// String elementLocal,
+// XSTypeDefinition type,
+// boolean declareNs,
+// boolean nillable,
+// boolean declareXsiType)
+// {
+// switch(type.getTypeCategory())
+// {
+// case XSTypeDefinition.SIMPLE_TYPE:
+// marshalSimpleType(elementNs,
+// elementLocal,
+// (XSSimpleTypeDefinition)type,
+// declareNs,
+// nillable,
+// declareXsiType
+// );
+// break;
+// case XSTypeDefinition.COMPLEX_TYPE:
+// marshalComplexType(elementNs, elementLocal, (XSComplexTypeDefinition)type,
declareNs, declareXsiType);
+// break;
+// default:
+// throw new IllegalStateException("Unexpected type category: " +
type.getTypeCategory()); //$NON-NLS-1$
+// }
+// }
+//
+// private void marshalSimpleType(String elementUri,
+// String elementLocal,
+// XSSimpleTypeDefinition type,
+// boolean declareNs,
+// boolean nillable,
+// boolean declareXsiType)
+// {
+// Object value = stack.peek();
+// if(value != null)
+// {
+// String prefix = getPrefix(elementUri);
+// boolean genPrefix = prefix == null && elementUri != null &&
elementUri.length() > 0;
+// if(genPrefix)
+// {
+// prefix = "ns_" + elementLocal; //$NON-NLS-1$
+// }
+//
+// AttributesImpl attrs = null;
+// String typeName = type.getName();
+// if(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
+// SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
+// type.getItemType() != null &&
+// (SimpleTypeBindings.XS_QNAME_NAME.equals(type.getItemType().getName()) ||
+// SimpleTypeBindings.XS_NOTATION_NAME.equals(type.getItemType().getName())
+// )
+// )
+// {
+// attrs = new AttributesImpl(5);
+// }
+//
+// String marshalled = marshalCharacters(elementUri, prefix, type, value,
attrs);
+//
+// if((declareNs || declareXsiType) && nsRegistry.size() > 0)
+// {
+// if(attrs == null)
+// {
+// attrs = new AttributesImpl(nsRegistry.size() + 1);
+// }
+// declareNs(attrs);
+// }
+//
+// if(declareXsiType)
+// {
+// declareXsiType(type, attrs);
+// }
+//
+// if(genPrefix)
+// {
+// if(attrs == null)
+// {
+// attrs = new AttributesImpl(1);
+// }
+// attrs.add(null, prefix, "xmlns:" + prefix, null,
(String)elementUri); //$NON-NLS-1$
+// }
+//
+// String qName = prefixLocalName(prefix, elementLocal);
+//
+// content.startElement(elementUri, elementLocal, qName, attrs);
+// content.characters(marshalled.toCharArray(), 0, marshalled.length());
+// content.endElement(elementUri, elementLocal, qName);
+// }
+// else
+// {
+// writeNillable(elementUri, elementLocal, nillable);
+// }
+// }
+//
+// private void marshalComplexType(String elementNsUri,
+// String elementLocalName,
+// XSComplexTypeDefinition type,
+// boolean declareNs,
+// boolean declareXsiType)
+// {
+// Object o = stack.peek();
+// XSParticle particle = type.getParticle();
+//
+// XSObjectList attributeUses = type.getAttributeUses();
+// int attrsTotal = declareNs || declareXsiType ?
+// nsRegistry.size() + attributeUses.getLength() + 1 :
+// attributeUses.getLength();
+// AttributesImpl attrs = attrsTotal > 0 ? new AttributesImpl(attrsTotal) :
null;
+//
+// if(declareNs && nsRegistry.size() > 0)
+// {
+// declareNs(attrs);
+// }
+//
+// String generatedPrefix = null;
+// if(declareXsiType)
+// {
+// generatedPrefix = declareXsiType(type, attrs);
+// if(generatedPrefix != null)
+// {
+// String typeNsWithGeneratedPrefix = type.getNamespace();
+// declareNs(attrs, generatedPrefix, typeNsWithGeneratedPrefix);
+// declareNamespace(generatedPrefix, typeNsWithGeneratedPrefix);
+// }
+// }
+//
+// String prefix = getPrefix(elementNsUri);
+// boolean genPrefix = prefix == null && elementNsUri != null &&
elementNsUri.length() > 0;
+// if(genPrefix)
+// {
+// // todo: it's possible that the generated prefix already mapped. this
should be fixed
+// prefix = "ns_" + elementLocalName; //$NON-NLS-1$
+// declareNamespace(prefix, elementNsUri);
+// if(attrs == null)
+// {
+// attrs = new AttributesImpl(1);
+// }
+// attrs.add(null, prefix, "xmlns:" + prefix, null, elementNsUri);
//$NON-NLS-1$
+// }
+//
+// for(int i = 0; i < attributeUses.getLength(); ++i)
+// {
+// currentAttribute = (XSAttributeUse)attributeUses.item(i);
+// XSAttributeDeclaration attrDec = currentAttribute.getAttrDeclaration();
+// String attrNs = attrDec.getNamespace();
+// String attrLocal = attrDec.getName();
+// Object attrValue = provider.getAttributeValue(o, ctx, attrNs, attrLocal);
+//
+// if(attrValue != null)
+// {
+// if(attrs == null)
+// {
+// attrs = new AttributesImpl(5);
+// }
+//
+// String attrPrefix = null;
+// if(attrNs != null)
+// {
+// attrPrefix = getPrefix(attrNs);
+// if(attrPrefix == null && attrNs != null &&
attrNs.length() > 0)
+// {
+// attrPrefix = "ns_" + attrLocal; //$NON-NLS-1$
+// attrs.add(null, attrPrefix, "xmlns:" + attrPrefix, null,
attrNs); //$NON-NLS-1$
+// }
+// }
+//
+// String qName = attrPrefix == null || attrPrefix.length() == 0 ? attrLocal :
attrPrefix + ":" + attrLocal; //$NON-NLS-1$
+//
+// // todo: this is a quick fix for boolean pattern (0|1 or true|false) should
be refactored
+// XSSimpleTypeDefinition attrType = attrDec.getTypeDefinition();
+// if(attrType.getItemType() != null)
+// {
+// XSSimpleTypeDefinition itemType = attrType.getItemType();
+// if(Constants.NS_XML_SCHEMA.equals(itemType.getNamespace()))
+// {
+// List list;
+// if(attrValue instanceof List)
+// {
+// list = (List)attrValue;
+// }
+// else if(attrValue.getClass().isArray())
+// {
+// list = Arrays.asList((Object[])attrValue);
+// }
+// else
+// {
+// throw new JBossXBRuntimeException("Expected value for list
type is an array or " + //$NON-NLS-1$
+// List.class.getName() +
+// " but got: " + //$NON-NLS-1$
+// attrValue
+// );
+// }
+//
+// if(Constants.QNAME_QNAME.getLocalPart().equals(itemType.getName()))
+// {
+// for(int listInd = 0; listInd < list.size(); ++listInd)
+// {
+// QName item = (QName)list.get(listInd);
+// String itemNs = item.getNamespaceURI();
+// if(itemNs != null && itemNs.length() > 0)
+// {
+// String itemPrefix;
+// if(itemNs.equals(elementNsUri))
+// {
+// itemPrefix = prefix;
+// }
+// else
+// {
+// itemPrefix = getPrefix(itemNs);
+// if(itemPrefix == null)
+// {
+// itemPrefix = attrLocal + listInd;
+// declareNs(attrs, itemPrefix, itemNs);
+// }
+// }
+// item = new QName(item.getNamespaceURI(),
item.getLocalPart(), itemPrefix);
+// list.set(listInd, item);
+// }
+// }
+// }
+//
+// attrValue = SimpleTypeBindings.marshalList(itemType.getName(), list,
null);
+// }
+// else
+// {
+// throw new JBossXBRuntimeException("Marshalling of list types
with item types not from " + //$NON-NLS-1$
+// Constants.NS_XML_SCHEMA + " is not supported."
//$NON-NLS-1$
+// );
+// }
+// }
+// else if(attrType.getLexicalPattern().item(0) != null
+// &&
+// attrType.derivedFrom(Constants.NS_XML_SCHEMA,
+// Constants.QNAME_BOOLEAN.getLocalPart(),
+// XSConstants.DERIVATION_RESTRICTION
+// ))
+// {
+// String item = attrType.getLexicalPattern().item(0);
+// if(item.indexOf('0') != -1 && item.indexOf('1')
!= -1)
+// {
+// attrValue = ((Boolean)attrValue).booleanValue() ? "1" :
"0"; //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// else
+// {
+// attrValue = ((Boolean)attrValue).booleanValue() ? "true" :
"false"; //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// }
+// else
if(Constants.QNAME_QNAME.getNamespaceURI().equals(attrType.getNamespace()) &&
+// Constants.QNAME_QNAME.getLocalPart().equals(attrType.getName()))
+// {
+// QName qNameValue = (QName)attrValue;
+//
+// String qNamePrefix = null;
+// boolean declarePrefix = false;
+// String ns = qNameValue.getNamespaceURI();
+// if(ns != null && ns.length() > 0)
+// {
+// qNamePrefix = getPrefix(ns);
+// if(qNamePrefix == null)
+// {
+// qNamePrefix = qNameValue.getPrefix();
+// if(qNamePrefix == null || qNamePrefix.length() == 0)
+// {
+// qNamePrefix = "ns_" + qNameValue.getLocalPart();
//$NON-NLS-1$
+// }
+// declareNs(attrs, qNamePrefix, ns);
+// nsRegistry.addPrefixMapping(qNamePrefix, ns);
+// declarePrefix = true;
+// }
+// }
+//
+// attrValue = SimpleTypeBindings.marshalQName(qNameValue, nsRegistry);
+//
+// if(declarePrefix)
+// {
+// nsRegistry.removePrefixMapping(qNamePrefix);
+// }
+// }
+// else
+// {
+// attrValue = attrValue.toString();
+// }
+//
+// attrs.add(attrNs,
+// attrLocal,
+// qName,
+// attrDec.getTypeDefinition().getName(),
+// attrValue.toString()
+// );
+// } // end if attrValue != null
+// else if( currentAttribute.getRequired()){
+// // its required and is not present. Must throw exception
+// String name = currentAttribute.getAttrDeclaration().getName();
+// throw new JBossXBRuntimeException("Required Attribute " + name +
" is not present"); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// }
+// currentAttribute = null;
+//
+// String characters = null;
+// if(type.getSimpleType() != null)
+// {
+// Object value = getSimpleContentValue(elementNsUri, elementLocalName, type);
+// if(value != null)
+// {
+// XSSimpleTypeDefinition simpleType = type.getSimpleType();
+// String typeName = simpleType.getName();
+// if(attrs == null &&
(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
+// SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
+// simpleType.getItemType() != null &&
+//
(SimpleTypeBindings.XS_QNAME_NAME.equals(simpleType.getItemType().getName()) ||
+//
SimpleTypeBindings.XS_NOTATION_NAME.equals(simpleType.getItemType().getName())
+// )
+// )
+// )
+// {
+// attrs = new AttributesImpl(5);
+// }
+//
+// characters = marshalCharacters(elementNsUri, prefix, simpleType, value,
attrs);
+// }
+// }
+//
+// String qName = prefixLocalName(prefix, elementLocalName);
+// content.startElement(elementNsUri, elementLocalName, qName, attrs);
+//
+// if(particle != null)
+// {
+// marshalParticle(particle, false);
+// }
+//
+// if(characters != null)
+// {
+// content.characters(characters.toCharArray(), 0, characters.length());
+// }
+// content.endElement(elementNsUri, elementLocalName, qName);
+//
+// if(genPrefix)
+// {
+// removePrefixMapping(prefix);
+// }
+//
+// if(generatedPrefix != null)
+// {
+// removePrefixMapping(generatedPrefix);
+// }
+// }
+//
+// private boolean marshalParticle(XSParticle particle, boolean declareNs)
+// {
+// boolean marshalled;
+// XSTerm term = particle.getTerm();
+// Object o;
+// Iterator i;
+// switch(term.getType())
+// {
+// case XSConstants.MODEL_GROUP:
+// o = stack.peek();
+// i = o != null && isRepeatable(particle) ? getIterator(o) : null;
+// if(i != null)
+// {
+// marshalled = true;
+// while(i.hasNext() && marshalled)
+// {
+// Object value = i.next();
+// stack.push(value);
+// marshalled = marshalModelGroup(particle, declareNs);
+// stack.pop();
+// }
+// }
+// else
+// {
+// marshalled = marshalModelGroup(particle, declareNs);
+// }
+// break;
+// case XSConstants.WILDCARD:
+// o = stack.peek();
+//
+// boolean popWildcardValue = false;
+// ObjectLocalMarshaller marshaller = null;
+// FieldToWildcardMapping mapping =
(FieldToWildcardMapping)field2WildcardMap.get(o.getClass());
+// if(mapping != null)
+// {
+// marshaller = mapping.marshaller;
+// o = mapping.fieldInfo.getValue(o);
+// stack.push(o);
+// popWildcardValue = true;
+// }
+//
+// i = o != null && isRepeatable(particle) ? getIterator(o) : null;
+// if(i != null)
+// {
+// marshalled = true;
+// while(i.hasNext() && marshalled)
+// {
+// Object value = i.next();
+// marshalled = marshalWildcardOccurence(particle, marshaller, value,
declareNs);
+// }
+// }
+// else
+// {
+// marshalled = marshalWildcardOccurence(particle, marshaller, o,
declareNs);
+// }
+//
+// if(popWildcardValue)
+// {
+// stack.pop();
+// }
+//
+// break;
+// case XSConstants.ELEMENT_DECLARATION:
+// XSElementDeclaration element = (XSElementDeclaration)term;
+// XSTypeDefinition type = element.getTypeDefinition();
+// o = getElementValue(element.getNamespace(), element.getName(), type);
+//
+// i = o != null && isRepeatable(particle) ? getIterator(o) : null;
+// if(i != null)
+// {
+// marshalled = true;
+// while(i.hasNext() && marshalled)
+// {
+// Object value = i.next();
+// marshalled =
+// marshalElementOccurence(element.getNamespace(),
+// element.getName(),
+// type,
+// value,
+// element.getNillable(),
+// particle.getMinOccurs() == 0,
+// declareNs
+// );
+// }
+// }
+// else
+// {
+// marshalled =
+// marshalElementOccurence(element.getNamespace(),
+// element.getName(),
+// type,
+// o,
+// element.getNillable(),
+// particle.getMinOccurs() == 0,
+// declareNs
+// );
+// }
+// break;
+// default:
+// throw new IllegalStateException("Unexpected term type: " +
term.getType()); //$NON-NLS-1$
+// }
+// return marshalled;
+// }
+//
+// private boolean marshalElementOccurence(String elementNs,
+// String elementLocal,
+// XSTypeDefinition type,
+// Object value,
+// boolean nillable,
+// boolean optional,
+// boolean declareNs)
+// {
+// boolean declareXsiType = false;
+// QName xsiTypeQName = null;
+// if(value != null)
+// {
+// xsiTypeQName = (QName)cls2TypeMap.get(value.getClass());
+// if(xsiTypeQName != null &&
+// !(type.getName().equals(xsiTypeQName.getLocalPart()) &&
+// type.getNamespace().equals(xsiTypeQName.getNamespaceURI())
+// ))
+// {
+// declareXsiType = true;
+// if(log.isTraceEnabled())
+// {
+// log.trace(value.getClass() + " is mapped to xsi:type " +
xsiTypeQName); //$NON-NLS-1$
+// }
+//
+// XSTypeDefinition xsiType =
model.getTypeDefinition(xsiTypeQName.getLocalPart(),
+// xsiTypeQName.getNamespaceURI()
+// );
+//
+// if(xsiType == null)
+// {
+// log.warn("Class " + //$NON-NLS-1$
+// value.getClass() +
+// " is mapped to type " + //$NON-NLS-1$
+// xsiTypeQName +
+// " but the type is not found in schema." //$NON-NLS-1$
+// );
+// }
+// // todo should check derivation also, i.e. if(xsiType.derivedFrom())
+// else
+// {
+// type = xsiType;
+// }
+// }
+// }
+//
+// stack.push(value);
+// boolean marshalled = marshalElement(elementNs,
+// elementLocal,
+// type,
+// optional,
+// nillable,
+// declareNs,
+// declareXsiType
+// );
+// stack.pop();
+//
+// return marshalled;
+// }
+//
+// private boolean marshalWildcardOccurence(XSParticle particle,
+// ObjectLocalMarshaller marshaller,
+// Object value,
+// boolean declareNs)
+// {
+// boolean marshalled = true;
+// if(marshaller != null)
+// {
+// marshaller.marshal(ctx, value);
+// }
+// else
+// {
+// stack.push(value);
+// marshalled = marshalWildcard(particle, declareNs);
+// stack.pop();
+// }
+// return marshalled;
+// }
+//
+// private boolean marshalWildcard(XSParticle particle, boolean declareNs)
+// {
+// XSWildcard wildcard = (XSWildcard)particle.getTerm();
+// Object o = stack.peek();
+// ClassMapping mapping = getClassMapping(o.getClass());
+// if(mapping == null)
+// {
+// // todo: YAH (yet another hack)
+// QName autoType = SimpleTypeBindings.typeQName(o.getClass());
+// if(autoType != null)
+// {
+// String marshalled = SimpleTypeBindings.marshal(autoType.getLocalPart(), o,
null);
+// content.characters(marshalled.toCharArray(), 0, marshalled.length());
+// return true;
+// }
+// else
+// {
+// if(ignoreUnresolvedWildcard)
+// {
+// log.warn("Failed to marshal wildcard. Class mapping not found for
" + //$NON-NLS-1$
+// o.getClass() +
+// "@" + //$NON-NLS-1$
+// o.hashCode() +
+// ": " + o //$NON-NLS-1$
+// );
+// return true;
+// }
+// else
+// {
+// throw new IllegalStateException("Failed to marshal wildcard. Class
mapping not found for " + //$NON-NLS-1$
+// o.getClass() +
+// "@" + //$NON-NLS-1$
+// o.hashCode() +
+// ": " + o //$NON-NLS-1$
+// );
+// }
+// }
+// }
+//
+// GenericObjectModelProvider parentProvider = this.provider;
+// Object parentRoot = this.root;
+// Stack parentStack = this.stack;
+// XSModel parentModel = this.model;
+//
+// this.root = o;
+// this.stack = new StackImpl();
+// this.model = mapping.schemaUrl == null ? this.model :
Util.loadSchema(mapping.schemaUrl, schemaResolver);
+// if(mapping.provider != null)
+// {
+// this.provider = mapping.provider;
+// }
+//
+// boolean marshalled;
+// if(mapping.elementName != null)
+// {
+// XSElementDeclaration elDec =
model.getElementDeclaration(mapping.elementName.getLocalPart(),
+// mapping.elementName.getNamespaceURI()
+// );
+//
+// if(elDec == null)
+// {
+// throw new JBossXBRuntimeException("Element " +
mapping.elementName + " is not declared in the schema."); //$NON-NLS-1$
//$NON-NLS-2$
+// }
+//
+// Object elementValue = provider.getRoot(root, null, elDec.getNamespace(),
elDec.getName());
+// marshalled = marshalElementOccurence(elDec.getNamespace(),
+// elDec.getName(),
+// elDec.getTypeDefinition(),
+// elementValue,
+// elDec.getNillable(),
+// particle.getMinOccurs() == 0,
+// declareNs
+// );
+// }
+// else if(mapping.typeName != null)
+// {
+// XSTypeDefinition typeDef =
model.getTypeDefinition(mapping.typeName.getLocalPart(),
+// mapping.typeName.getNamespaceURI()
+// );
+//
+// if(typeDef == null)
+// {
+// List typeNames = new ArrayList();
+// XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
+// for(int i = 0; i < types.getLength(); ++i)
+// {
+// XSObject type = types.item(i);
+// if(!Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
+// {
+// typeNames.add(new QName(type.getNamespace(), type.getName()));
+// }
+// }
+// throw new JBossXBRuntimeException("Type " + //$NON-NLS-1$
+// mapping.typeName +
+// " is not defined in the schema." + //$NON-NLS-1$
+// " Defined types are: " + typeNames //$NON-NLS-1$
+// );
+// }
+//
+// Object elementValue = provider.getRoot(root, null, wildcard.getNamespace(),
wildcard.getName());
+// marshalled =
+// marshalElementOccurence(wildcard.getNamespace(),
+// wildcard.getName(),
+// typeDef,
+// elementValue,
+// true,
+// particle.getMinOccurs() == 0,
+// declareNs
+// );
+// }
+// else
+// {
+// throw new JBossXBRuntimeException("Class mapping for " +
//$NON-NLS-1$
+// mapping.cls +
+// " is associated with neither global element name nor global type
name." //$NON-NLS-1$
+// );
+// }
+//
+// this.root = parentRoot;
+// this.provider = parentProvider;
+// this.stack = parentStack;
+// this.model = parentModel;
+//
+// return marshalled;
+// }
+//
+// private boolean marshalModelGroup(XSParticle particle, boolean declareNs)
+// {
+// XSModelGroup modelGroup = (XSModelGroup)particle.getTerm();
+// boolean marshalled;
+// switch(modelGroup.getCompositor())
+// {
+// case XSModelGroup.COMPOSITOR_ALL:
+// marshalled = marshalModelGroupAll(modelGroup.getParticles(), declareNs);
+// break;
+// case XSModelGroup.COMPOSITOR_CHOICE:
+// marshalled = marshalModelGroupChoice(modelGroup.getParticles(),
declareNs);
+// break;
+// case XSModelGroup.COMPOSITOR_SEQUENCE:
+// marshalled = marshalModelGroupSequence(modelGroup.getParticles(),
declareNs);
+// break;
+// default:
+// throw new IllegalStateException("Unexpected compsitor: " +
modelGroup.getCompositor()); //$NON-NLS-1$
+// }
+// return marshalled;
+// }
+//
+// private boolean marshalModelGroupAll(XSObjectList particles, boolean declareNs)
+// {
+// boolean marshalled = false;
+// for(int i = 0; i < particles.getLength(); ++i)
+// {
+// XSParticle particle = (XSParticle)particles.item(i);
+// marshalled |= marshalParticle(particle, declareNs);
+// }
+// return marshalled;
+// }
+//
+// private boolean marshalModelGroupChoice(XSObjectList particles, boolean declareNs)
+// {
+// boolean marshalled = false;
+// Content mainContent = this.content;
+// for(int i = 0; i < particles.getLength() && !marshalled; ++i)
+// {
+// XSParticle particle = (XSParticle)particles.item(i);
+// this.content = new Content();
+// marshalled = marshalParticle(particle, declareNs);
+// }
+//
+// if(marshalled)
+// {
+// mainContent.append(this.content);
+// }
+// this.content = mainContent;
+//
+// return marshalled;
+// }
+//
+// private boolean marshalModelGroupSequence(XSObjectList particles, boolean
declareNs)
+// {
+// boolean marshalled = true;
+// for(int i = 0; i < particles.getLength(); ++i)
+// {
+// XSParticle particle = (XSParticle)particles.item(i);
+// marshalled &= marshalParticle(particle, declareNs);
+// }
+// return marshalled;
+// }
+//
+// private String marshalCharacters(String elementUri,
+// String elementPrefix,
+// XSSimpleTypeDefinition type,
+// Object value,
+// AttributesImpl attrs)
+// {
+// String marshalled;
+// if(type.getItemType() != null)
+// {
+// XSSimpleTypeDefinition itemType = type.getItemType();
+// if(Constants.NS_XML_SCHEMA.equals(itemType.getNamespace()))
+// {
+// List list;
+// if(value instanceof List)
+// {
+// list = (List)value;
+// }
+// else if(value.getClass().isArray())
+// {
+// list = asList(value);
+// }
+// else
+// {
+// // todo: qname are also not yet supported
+// throw new JBossXBRuntimeException(
+// "Expected value for list type is an array or " +
List.class.getName() + " but got: " + value //$NON-NLS-1$ //$NON-NLS-2$
+// );
+// }
+//
+// marshalled = SimpleTypeBindings.marshalList(itemType.getName(), list,
null);
+// }
+// else
+// {
+// throw new JBossXBRuntimeException("Marshalling of list types with item
types not from " + //$NON-NLS-1$
+// Constants.NS_XML_SCHEMA + " is not supported." //$NON-NLS-1$
+// );
+// }
+// }
+// else if(Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
+// {
+// String typeName = type.getName();
+//
+// String prefix = null;
+// boolean removePrefix = false;
+// if(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
+// SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName))
+// {
+// QName qName = (QName)value;
+// if(qName.getNamespaceURI() != null &&
qName.getNamespaceURI().length() > 0)
+// {
+// prefix = nsRegistry.getPrefix(qName.getNamespaceURI());
+// if(prefix == null)
+// {
+// prefix = qName.getPrefix();
+// if(prefix == null || prefix.length() == 0)
+// {
+// prefix = qName.getLocalPart() + "_ns"; //$NON-NLS-1$
+// }
+// nsRegistry.addPrefixMapping(prefix, qName.getNamespaceURI());
+// declareNs(attrs, prefix, qName.getNamespaceURI());
+//
+// removePrefix = true;
+// }
+// }
+// }
+// marshalled = SimpleTypeBindings.marshal(typeName, value, nsRegistry);
+//
+// if(removePrefix)
+// {
+// nsRegistry.removePrefixMapping(prefix);
+// }
+// }
+// // todo: this is a quick fix for boolean pattern (0|1 or true|false) should be
refactored
+// else if(type.getLexicalPattern().item(0) != null
+// &&
+// type.derivedFrom(Constants.NS_XML_SCHEMA,
+// Constants.QNAME_BOOLEAN.getLocalPart(),
+// XSConstants.DERIVATION_RESTRICTION
+// ))
+// {
+// String item = type.getLexicalPattern().item(0);
+// if(item.indexOf('0') != -1 && item.indexOf('1') !=
-1)
+// {
+// marshalled = ((Boolean)value).booleanValue() ? "1" :
"0";//$NON-NLS-1$ //$NON-NLS-2$
+// }
+// else
+// {
+// marshalled = ((Boolean)value).booleanValue() ? "true" :
"false";//$NON-NLS-1$ //$NON-NLS-2$
+// }
+// }
+// else
+// {
+// StringList lexicalEnumeration = type.getLexicalEnumeration();
+// if(lexicalEnumeration != null && lexicalEnumeration.getLength() >
0)
+// {
+// Method getValue;
+// try
+// {
+// getValue = value.getClass().getMethod("value", null);
//$NON-NLS-1$
+// }
+// catch(NoSuchMethodException e)
+// {
+// try
+// {
+// getValue = value.getClass().getMethod("getValue", null);
//$NON-NLS-1$
+// }
+// catch(NoSuchMethodException e1)
+// {
+// List values = new ArrayList(lexicalEnumeration.getLength());
+// for(int i = 0; i < lexicalEnumeration.getLength(); ++i)
+// {
+// values.add(lexicalEnumeration.item(i));
+// }
+//
+// throw new JBossXBRuntimeException("Failed to find neither
value() nor getValue() in " + //$NON-NLS-1$
+// value.getClass() +
+// " which is bound to enumeration type (" + //$NON-NLS-1$
+// type.getNamespace() +
+// ", " + //$NON-NLS-1$
+// type.getName() + "): " + values //$NON-NLS-1$
+// );
+// }
+// }
+//
+// try
+// {
+// value = getValue.invoke(value, null);
+// }
+// catch(Exception e)
+// {
+// throw new JBossXBRuntimeException(
+// "Failed to invoke getValue() on " + value + " to get
the enumeration value", e//$NON-NLS-1$ //$NON-NLS-2$
+// );
+// }
+// }
+//
+// marshalled = marshalCharacters(elementUri,
+// elementPrefix,
+// (XSSimpleTypeDefinition)type.getBaseType(),
+// value, attrs
+// );
+// }
+// return marshalled;
+// }
+//
+// /**
+// * Adds xsi:type attribute and optionally declares namespaces for xsi and type's
namespace.
+// * @param type the type to declare xsi:type attribute for
+// * @param attrs the attributes to add xsi:type attribute to
+// * @return prefix for the type's ns if it was generated
+// */
+// private String declareXsiType(XSTypeDefinition type, AttributesImpl attrs)
+// {
+// String result = null;
+// String xsiPrefix = nsRegistry.getPrefix(Constants.NS_XML_SCHEMA_INSTANCE);
+// if(xsiPrefix == null)
+// {
+// attrs.add(Constants.NS_XML_SCHEMA, "xmlns", "xmlns:xsi",
null, Constants.NS_XML_SCHEMA_INSTANCE);//$NON-NLS-1$ //$NON-NLS-2$
+// xsiPrefix = "xsi"; //$NON-NLS-1$
+// }
+//
+// String pref = getPrefix(type.getNamespace());
+// if(pref == null)
+// {
+// // the ns is not declared
+// result = pref = type.getName() + "_ns"; //$NON-NLS-1$
+// }
+//
+// String typeQName = pref == null ? type.getName() : pref + ':' +
type.getName();
+// attrs.add(Constants.NS_XML_SCHEMA_INSTANCE, "type", xsiPrefix +
":type", null, typeQName);//$NON-NLS-1$ //$NON-NLS-2$
+// return result;
+// }
+//
+// private Object getElementValue(String elementNs, String elementLocal,
XSTypeDefinition type)
+// {
+// Object value;
+// Object peeked = stack.isEmpty() ? root : stack.peek();
+// if(peeked == null)
+// {
+// value = null;
+// }
+// else if(peeked instanceof Collection || peeked.getClass().isArray())
+// {
+// // collection is the provider
+// value = peeked;
+// }
+// else
+// {
+// XSTypeDefinition parentType = currentElementType;
+// currentElementType = type;
+//
+// value = provider.getChildren(peeked, ctx, elementNs, elementLocal);
+// if(value == null)
+// {
+// value = provider.getElementValue(peeked, ctx, elementNs, elementLocal);
+// }
+//
+// currentElementType = parentType;
+// }
+// return value;
+// }
+//
+// private Object getSimpleContentValue(String elementNs, String elementLocal,
XSTypeDefinition type)
+// {
+// Object value;
+// Object peeked = stack.isEmpty() ? root : stack.peek();
+// if(peeked == null)
+// {
+// value = null;
+// }
+// else
+// {
+// XSTypeDefinition parentType = currentElementType;
+// currentElementType = type;
+// value = provider.getElementValue(peeked, ctx, elementNs, elementLocal);
+// currentElementType = parentType;
+// }
+// return value;
+// }
+//
+// private void writeNillable(String elementNs, String elementLocal, boolean nillable)
+// {
+// if(!supportNil)
+// {
+// return;
+// }
+//
+// if(!nillable)
+// {
+// throw new JBossXBRuntimeException("Failed to marshal " +
//$NON-NLS-1$
+// new QName(elementNs, elementLocal) +
+// ": Java value is null but the element is not nillable."
//$NON-NLS-1$
+// );
+// }
+//
+// AttributesImpl attrs;
+// String prefix = getPrefix(elementNs);
+// if(prefix == null && elementNs != null && elementNs.length() >
0)
+// {
+// prefix = "ns_" + elementLocal; //$NON-NLS-1$
+// attrs = new AttributesImpl(2);
+// attrs.add(null, prefix, "xmlns:" + prefix, null, elementNs);
//$NON-NLS-1$
+// }
+// else
+// {
+// attrs = new AttributesImpl(1);
+// }
+//
+// String xsiPrefix = getPrefix(Constants.NS_XML_SCHEMA_INSTANCE);
+// if(xsiPrefix == null)
+// {
+// xsiPrefix = "xsi"; //$NON-NLS-1$
+// attrs.add(null,
+// xsiPrefix,
+// "xmlns:xsi", //$NON-NLS-1$
+// null,
+// Constants.NS_XML_SCHEMA_INSTANCE
+// );
+// }
+//
+// String nilQName = xsiPrefix + ":nil"; //$NON-NLS-1$
+// attrs.add(Constants.NS_XML_SCHEMA_INSTANCE, "nil", nilQName, null,
"1"); //$NON-NLS-1$ //$NON-NLS-2$
+//
+// String qName = prefixLocalName(prefix, elementLocal);
+// content.startElement(elementNs, elementLocal, qName, attrs);
+// content.endElement(elementNs, elementLocal, qName);
+// }
+//
+// private static boolean isArrayWrapper(XSTypeDefinition type)
+// {
+// boolean is = false;
+// if(XSTypeDefinition.COMPLEX_TYPE == type.getTypeCategory())
+// {
+// XSComplexTypeDefinition cType = (XSComplexTypeDefinition)type;
+// XSParticle particle = cType.getParticle();
+// if(particle != null)
+// {
+// is = particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1;
+// }
+// }
+// return is;
+// }
+//
+// private Iterator getIterator(Object value)
+// {
+// Iterator i = null;
+// if(value instanceof Collection)
+// {
+// i = ((Collection)value).iterator();
+// }
+// else if(value.getClass().isArray())
+// {
+// final Object arr = value;
+// i = new Iterator()
+// {
+// private int curInd = 0;
+// private int length = Array.getLength(arr);
+//
+// public boolean hasNext()
+// {
+// return curInd < length;
+// }
+//
+// public Object next()
+// {
+// return Array.get(arr, curInd++);
+// }
+//
+// public void remove()
+// {
+// throw new UnsupportedOperationException("remove is not
implemented."); //$NON-NLS-1$
+// }
+// };
+// }
+// else if(value instanceof Iterator)
+// {
+// i = (Iterator)value;
+// }
+// else
+// {
+// //throw new JBossXBRuntimeException("Unexpected type for children: "
+ value.getClass());
+// }
+// return i;
+// }
+//
+// private static boolean isRepeatable(XSParticle particle)
+// {
+// return particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1 ||
particle.getMinOccurs() > 1;
+// }
+//
+// private static final List asList(final Object arr)
+// {
+// return new AbstractList()
+// {
+// private final Object array = arr;
+//
+// public Object get(int index)
+// {
+// return Array.get(array, index);
+// }
+//
+// public int size()
+// {
+// return Array.getLength(array);
+// }
+// };
+// }
}
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -10,84 +10,200 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.core.model.internal.xb;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
-import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.jboss.ide.eclipse.archives.core.ArchivesCore;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
import org.jboss.ide.eclipse.archives.core.model.internal.ArchiveImpl;
-import org.jboss.xb.binding.JBossXBException;
-import org.jboss.xb.binding.JBossXBRuntimeException;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
-import org.xml.sax.SAXException;
+
/**
* This class is responsible for binding some xml file to it's proper
* objects. In short, it marshalls and unmarshalls the data.
* @author Marshall
* @author Rob Stryker
*/
-public class XMLBinding {
+public class XMLBinding {
+
+ public static class XbException extends Exception {
+ private Exception parent;
+ public XbException(Exception e) {
+ super();
+ parent = e;
+ }
+ public Exception getException() {
+ return parent;
+ }
+ public String getMessage() {
+ return parent.getCause() == null ? parent.getMessage() :
parent.getCause().getMessage();
+ }
+ public Throwable getCause() {
+ return parent;
+ }
+ }
+
+ public static String serializePackages(XbPackages packages, IProgressMonitor monitor)
throws XbException {
+ try {
+ StringWriter sw = new StringWriter();
+ XMLBinding.marshall(packages, sw, monitor);
+ return new String(sw.toString());
+ } catch( Exception e ) {
+ throw new XbException(e);
+ }
+ }
+ public static void marshallToFile(XbPackages element, IPath filePath, IProgressMonitor
monitor) throws XbException {
+ OutputStreamWriter writer = null;
+ try {
+ writer = new OutputStreamWriter(new FileOutputStream(filePath.toFile()));
+ XMLBinding.marshall(element, writer, monitor);
+ } catch( XbException xbe ) {
+ throw xbe;
+ } catch( IOException ioe ) {
+ throw new XbException(ioe);
+ }
+ finally {
+ try {
+ if( writer != null ) writer.close();
+ } catch( IOException ioe) {}
+ }
+ }
- public static final int NUM_UNMARSHAL_MONITOR_STEPS = 3;
- public static final int NUM_MARSHALL_MONITOR_STEPS = 2;
+ public static String marshall(IArchive topLevelArchive, IProgressMonitor monitor )
throws XbException {
+ if( topLevelArchive.isTopLevel() && topLevelArchive instanceof ArchiveImpl ) {
+ XbPackages packs =
(XbPackages)((ArchiveImpl)topLevelArchive).getNodeDelegate().getParent();
+ StringWriter sw = new StringWriter();
+ marshall(packs, sw, monitor);
+ return sw.toString();
+ }
+ return null;
+ }
- private static URL schema =
XMLBinding.class.getClassLoader().getResource("packages.xsd"); //$NON-NLS-1$
- private static URL log4jxml =
XMLBinding.class.getClassLoader().getResource("log4j.xml"); //$NON-NLS-1$
- private static SchemaBinding binding;
+ public static void marshall (final XbPackages element, final Writer writer,
+ final IProgressMonitor monitor) throws XbException {
+ XMLMemento root = XMLMemento.createWriteRoot("packages"); //$NON-NLS-1$
+ root.putString("version", new Double(element.getVersion()).toString());
//$NON-NLS-1$
+ List packagesToAdd = element.getChildren(XbPackage.class);
+ List props = element.getChildren(XbProperties.class);
+ marshallAddPackages(root, nullSafe(packagesToAdd));
+ marshallAddProperties(root, nullSafe(props));
+ try{
+ String s = root.saveToString();
+ writer.write(s);
+ } catch(IOException ioe) {
+ throw new XbException(ioe);
+ }
+ }
+ private static List nullSafe(List list) {
+ return list == null ? new ArrayList() : list;
+ }
+ private static boolean isEmpty(String s) {
+ return s != null && !"".equals(s); //$NON-NLS-1$
+ }
+ private static void marshallAddPackages(XMLMemento memento, List packages) throws
XbException {
+ Iterator i = packages.iterator();
+ while(i.hasNext()) {
+ XMLMemento childMemento = (XMLMemento)memento.createChild("package");
//$NON-NLS-1$
+ XbPackage childXb = (XbPackage)i.next();
+ if( childXb.getName() == null )
+ throw new XbException(new Exception("Element 'package' missing attribute
'name'")); //$NON-NLS-1$
+ childMemento.putString("name", childXb.getName()); //$NON-NLS-1$
+ if( !isEmpty(childXb.getPackageType()) )
+ childMemento.putString("type", childXb.getPackageType()); //$NON-NLS-1$
+ if( !isEmpty( childXb.getToDir()) )
+ childMemento.putString("todir", childXb.getToDir()); //$NON-NLS-1$
+ if( !isEmpty(childXb.getId() ) )
+ childMemento.putString("id", childXb.getId()); //$NON-NLS-1$
+ childMemento.putString("exploded", new
Boolean(childXb.isExploded()).toString()); //$NON-NLS-1$
+ childMemento.putString("inWorkspace", new
Boolean(childXb.isInWorkspace()).toString()); //$NON-NLS-1$
- private static boolean initialized = false;
+ // Add children
+ marshallAddPackages(childMemento, nullSafe(childXb.getChildren(XbPackage.class)));
+ addFileset(childMemento, nullSafe(childXb.getChildren(XbFileSet.class)));
+ addLibFileset(childMemento, nullSafe(childXb.getChildren(XbLibFileSet.class)));
+ addFolders(childMemento, nullSafe(childXb.getChildren(XbFolder.class)));
+ marshallAddProperties(childMemento,
nullSafe(childXb.getChildren(XbProperties.class)));
+ }
+ }
- static {
- System.setProperty("log4j.configuration", log4jxml.toString());
//$NON-NLS-1$
+ private static void addFolders(XMLMemento memento, List folders) throws XbException {
+ Iterator i = folders.iterator();
+ while(i.hasNext()) {
+ XMLMemento childMemento = (XMLMemento)memento.createChild("folder");
//$NON-NLS-1$
+ XbFolder childXb = (XbFolder)i.next();
+ if( childXb.getName() == null )
+ throw new XbException(new Exception("Element 'folder' missing attribute
'name'")); //$NON-NLS-1$
+ childMemento.putString("name", childXb.getName()); //$NON-NLS-1$
+
+ // Add children
+ marshallAddPackages(childMemento, nullSafe(childXb.getChildren(XbPackage.class)));
+ addFileset(childMemento, nullSafe(childXb.getChildren(XbFileSet.class)));
+ addLibFileset(childMemento, nullSafe(childXb.getChildren(XbLibFileSet.class)));
+ addFolders(childMemento, nullSafe(childXb.getChildren(XbFolder.class)));
+ marshallAddProperties(childMemento,
nullSafe(childXb.getChildren(XbProperties.class)));
+ }
}
- public static void init ()
- {
- try {
- InputStream stream = schema.openStream();
- binding = XsdBinder.bind(stream, "UTF-8", (String)null); //$NON-NLS-1$
- stream.close();
- initialized = true;
- } catch (IOException e) {
- ArchivesCore.getInstance().getLogger().log(IStatus.ERROR, e.getMessage(), e);
+ private static void addFileset(XMLMemento memento, List xbList) throws XbException {
+ Iterator i = xbList.iterator();
+ while(i.hasNext()) {
+ XMLMemento fsMemento = (XMLMemento)memento.createChild("fileset");
//$NON-NLS-1$
+ XbFileSet fsXb = (XbFileSet)i.next();
+ if( fsXb.getDir() == null )
+ throw new XbException(new Exception("Element 'fileset' missing attribute
'dir'")); //$NON-NLS-1$
+ if( fsXb.getIncludes() == null )
+ throw new XbException(new Exception("Element 'fileset' missing attribute
'includes'")); //$NON-NLS-1$
+
+ fsMemento.putString("dir", fsXb.getDir()); //$NON-NLS-1$
+ fsMemento.putString("includes", fsXb.getIncludes()); //$NON-NLS-1$
+ if( !isEmpty(fsXb.getExcludes()))
+ fsMemento.putString("excludes", fsXb.getExcludes()); //$NON-NLS-1$
+ fsMemento.putString("inWorkspace",new
Boolean(fsXb.isInWorkspace()).toString()); //$NON-NLS-1$
+ fsMemento.putString("flatten", new Boolean(fsXb.isFlatten()).toString());
//$NON-NLS-1$
+ marshallAddProperties(fsMemento, nullSafe(fsXb.getChildren(XbProperties.class)));
}
}
- private static void binderSandbox (XbRunnable runnable) throws XbException {
- ClassLoader original = Thread.currentThread().getContextClassLoader();
- ClassLoader myCL = XMLBinding.class.getClassLoader();
- Thread.currentThread().setContextClassLoader(myCL);
- XbException e = null;
- try {
- runnable.run();
- } catch( XbException ex ) {
- e = ex;
+ private static void addLibFileset(XMLMemento memento, List xbList) {
+ Iterator i = xbList.iterator();
+ while(i.hasNext()) {
+ XMLMemento fsMemento = (XMLMemento)memento.createChild("lib-fileset");
//$NON-NLS-1$
+ XbLibFileSet fsXb = (XbLibFileSet)i.next();
+ if( !isEmpty(fsXb.getId()))
+ fsMemento.putString("name", fsXb.getId()); //$NON-NLS-1$
+ marshallAddProperties(fsMemento, nullSafe(fsXb.getChildren(XbProperties.class)));
}
- Thread.currentThread().setContextClassLoader(original);
- if( e != null )
- throw e;
}
- public static XbPackages unmarshal( String input, IProgressMonitor monitor ) throws
XbException {
- return unmarshal(new ByteArrayInputStream(input.getBytes()), monitor);
+ private static void marshallAddProperties(XMLMemento memento, List properties) {
+ // should only have one "properties"
+ XbProperties propsObj = properties.size() == 0 ? null :
(XbProperties)properties.get(0);
+ XMLMemento props = (XMLMemento)memento.createChild("properties");
//$NON-NLS-1$
+ if( propsObj != null ) {
+ List indivProps = propsObj.getAllChildren();
+ Iterator j = indivProps.iterator();
+ while(j.hasNext()) {
+ XbProperty prop = (XbProperty)j.next();
+ XMLMemento propMemento = (XMLMemento) props.createChild("property");
//$NON-NLS-1$
+ propMemento.putString("name", prop.getName()); //$NON-NLS-1$
+ propMemento.putString("value", prop.getValue()); //$NON-NLS-1$
+ }
+ }
}
public static XbPackages unmarshal(File file, IProgressMonitor monitor) throws
XbException {
@@ -102,127 +218,186 @@
}
protected static XbPackages unmarshal (final InputStream in,
- final IProgressMonitor monitor) throws XbException {
- if( !initialized) init();
- final XbPackages[] element = new XbPackages[1];
- element[0] = null;
- XbRunnable runnable = new XbRunnable() {
- public void run () throws XbException {
- try {
- ArchivesUnmarshallerImpl unmarshaller = new ArchivesUnmarshallerImpl();
- monitor.worked(1);
- binding.setStrictSchema(true);
- unmarshaller.setValidation(true);
-
unmarshaller.getParser().setFeature("http://apache.org/xml/features/...;,
true); //$NON-NLS-1$
-
unmarshaller.getParser().setProperty("http://apache.org/xml/properti...;,
schema.toExternalForm()); //$NON-NLS-1$
- Object xmlObject = unmarshaller.unmarshal(in, binding);
- monitor.worked(1);
-
- element[0] = (XbPackages) xmlObject;
- monitor.worked(1);
-
- } catch (JBossXBException e) {
- throw new XbException(e);
- }
+ final IProgressMonitor monitor) throws XbException {
+ XMLMemento root = XMLMemento.createReadRoot(in);
+ if( root == null ) {
+ throw new XbException(new Exception("Unable to parse xml string"));
//$NON-NLS-1$
+ }
+ String versionString = root.getString("version"); //$NON-NLS-1$
+ System.out.println("unmarshalling: " + versionString); //$NON-NLS-1$
+ XbPackages packs = new XbPackages();
+ Double d = IArchiveModelRootNode.DESCRIPTOR_VERSION_1_0;
+ if( versionString != null ) {
+ try {
+ d = Double.parseDouble(versionString);
+ } catch(NumberFormatException nfe ) {
+ throw new XbException(nfe);
}
- };
+ }
+ packs.setVersion(d);
- binderSandbox(runnable);
- return element[0];
+ IMemento[] packageChildren = root.getChildren("package"); //$NON-NLS-1$
+ unmarshallPackageList(packs, packageChildren);
+ IMemento[] propertiesChild = root.getChildren("properties"); //$NON-NLS-1$
+ if( propertiesChild != null && propertiesChild.length == 1)
+ unmarshallProperties(packs, propertiesChild[0]);
+ return packs;
}
- public static String marshall(IArchive topLevelArchive, IProgressMonitor monitor )
throws XbException {
- if( topLevelArchive.isTopLevel() && topLevelArchive instanceof ArchiveImpl ) {
- XbPackages packs =
(XbPackages)((ArchiveImpl)topLevelArchive).getNodeDelegate().getParent();
- StringWriter sw = new StringWriter();
- marshall(packs, sw, monitor);
- return sw.toString();
- }
- return null;
- }
+ private static void unmarshallPackageList(XbPackageNodeWithProperties packs, IMemento[]
packageChildren) throws XbException {
+ for( int i = 0; i < packageChildren.length; i++ ) {
+ XbPackage pack = new XbPackage();
+ // name, type, toDir, exploded, inWorkspace, id
+ String name = packageChildren[i].getString("name"); //$NON-NLS-1$
+ String type = packageChildren[i].getString("type"); //$NON-NLS-1$
+ String toDir = packageChildren[i].getString("todir"); //$NON-NLS-1$
+ String id = packageChildren[i].getString("id"); //$NON-NLS-1$
+ String exploded = packageChildren[i].getString("exploded"); //$NON-NLS-1$
+ String inWorkspace = packageChildren[i].getString("inWorkspace");
//$NON-NLS-1$
+ String exploded2 = exploded == null ? "" : exploded; //$NON-NLS-1$
+ String inWorkspace2 = inWorkspace == null ? "" : inWorkspace; //$NON-NLS-1$
+ boolean explodedValid = ("true".equals(exploded2.toLowerCase()) ||
"false".equals(exploded2.toLowerCase())); //$NON-NLS-1$ //$NON-NLS-2$
+ boolean inWorkspaceValid = ("true".equals(inWorkspace2.toLowerCase()) ||
"false".equals(inWorkspace2.toLowerCase())); //$NON-NLS-1$ //$NON-NLS-2$
+ boolean bExploded = explodedValid ? Boolean.parseBoolean(exploded) : false;
+ boolean bInWorkspace = inWorkspaceValid ? Boolean.parseBoolean(inWorkspace) : true;
+ pack.setName(name);
+ pack.setPackageType(type);
+ pack.setToDir(toDir);
+ pack.setId(id);
+ pack.setExploded(bExploded);
+ pack.setInWorkspace(bInWorkspace);
+
+ if( name == null )
+ throw new XbException(new Exception("Element 'package' missing required
attribute 'name'")); //$NON-NLS-1$
- public static void marshallToFile(XbPackages element, IPath filePath, IProgressMonitor
monitor) throws XbException {
- OutputStreamWriter writer = null;
- try {
- writer = new OutputStreamWriter(new FileOutputStream(filePath.toFile()));
- XMLBinding.marshall(element, writer, monitor);
- } catch( XbException xbe ) {
- throw xbe;
- } catch( IOException ioe ) {
- throw new XbException(ioe);
- }
- finally {
- try {
- if( writer != null ) writer.close();
- } catch( IOException ioe) {}
- }
- }
+ // package
+ IMemento[] inner = packageChildren[i].getChildren("package"); //$NON-NLS-1$
+ if( inner != null && inner.length == 1)
+ unmarshallPackageList(pack, inner);
- public static void marshall (final XbPackages element, final Writer writer,
- final IProgressMonitor monitor) throws XbException {
- if( !initialized) init();
- binderSandbox(new XbRunnable() {
- public void run () throws XbException {
- Exception f = null;
- InputStream stream = null;
- try {
- stream = schema.openStream();
- monitor.worked(1);
+ // fileset
+ IMemento[] fsets = packageChildren[i].getChildren("fileset"); //$NON-NLS-1$
+ if( fsets != null && fsets.length == 1)
+ unmarshallFilesets(pack, fsets);
- StrictXercesXSMarshaller marshaller = new StrictXercesXSMarshaller();
- marshaller.marshal(new InputStreamReader(stream), new XbPackagesObjectProvider(),
element, writer);
- monitor.worked(1);
- } catch (IOException e) {
- f = e;
- } catch (SAXException e) {
- f = e;
- } catch (ParserConfigurationException e) {
- f = e;
- } catch (JBossXBRuntimeException e ) {
- f = e;
- } finally {
- if( stream != null ) {
- try {
- stream.close();
- } catch(IOException ioe) {}
- }
- }
- if( f != null ) {
- throw new XbException(f);
- }
- }
- });
- }
+ // lib-fileset
+ IMemento[] libfsets = packageChildren[i].getChildren("lib-fileset");
//$NON-NLS-1$
+ if( libfsets != null && libfsets.length == 1)
+ unmarshallLibFilesets(pack, libfsets);
- public static String serializePackages(XbPackages packages, IProgressMonitor monitor)
throws XbException {
- try {
- StringWriter sw = new StringWriter();
- XMLBinding.marshall(packages, sw, monitor);
- return new String(sw.toString());
- } catch( Exception e ) {
- throw new XbException(e);
+ // folder
+ IMemento[] folders = packageChildren[i].getChildren("folder");
//$NON-NLS-1$
+ if( folders != null && folders.length == 1)
+ unmarshallFolders(pack, folders);
+
+ // properties
+ IMemento[] propertiesChild = packageChildren[i].getChildren("properties");
//$NON-NLS-1$
+ if( propertiesChild != null && propertiesChild.length == 1)
+ unmarshallProperties(packs, propertiesChild[0]);
+
+ packs.addChild(pack);
}
}
+ private static void unmarshallFolders(XbPackageNodeWithProperties node, IMemento[]
folders) throws XbException {
+ for( int i = 0; i < folders.length; i++ ) {
+ XbFolder folder = new XbFolder();
+ // name, type, toDir, exploded, inWorkspace, id
+ String name = folders[i].getString("name"); //$NON-NLS-1$
+ folder.setName(name);
+ if( name == null )
+ throw new XbException(new Exception("Element 'folder' missing required
attribute 'name'")); //$NON-NLS-1$
+ // package
+ IMemento[] inner = folders[i].getChildren("package"); //$NON-NLS-1$
+ if( inner != null && inner.length == 1)
+ unmarshallPackageList(folder, inner);
- public static interface XbRunnable {
- public void run() throws XbException;
+ // fileset
+ IMemento[] fsets = folders[i].getChildren("fileset"); //$NON-NLS-1$
+ if( fsets != null && fsets.length == 1)
+ unmarshallFilesets(folder, fsets);
+
+ // lib-fileset
+ IMemento[] libfsets = folders[i].getChildren("lib-fileset"); //$NON-NLS-1$
+ if( libfsets != null && libfsets.length == 1)
+ unmarshallLibFilesets(folder, libfsets);
+
+ // folder
+ IMemento[] folders2 = folders[i].getChildren("folder"); //$NON-NLS-1$
+ if( folders2 != null && folders2.length == 1)
+ unmarshallFolders(folder, folders2);
+
+ // properties
+ IMemento[] propertiesChild = folders[i].getChildren("properties");
//$NON-NLS-1$
+ if( propertiesChild != null && propertiesChild.length == 1)
+ unmarshallProperties(folder, propertiesChild[0]);
+
+ node.addChild(folder);
+ }
}
+ private static void unmarshallFilesets(XbPackageNodeWithProperties node, IMemento[] fs)
throws XbException {
+ for( int i = 0; i < fs.length; i++ ) {
+ XbFileSet fileset = new XbFileSet();
+ // name, type, toDir, exploded, inWorkspace, id
+ String dir = fs[i].getString("dir"); //$NON-NLS-1$
+ String inc = fs[i].getString("includes"); //$NON-NLS-1$
+ String exc = fs[i].getString("excludes"); //$NON-NLS-1$
+ String inWorkspace = fs[i].getString("inWorkspace"); //$NON-NLS-1$
+ String inWorkspace2 = inWorkspace == null ? "" : inWorkspace; //$NON-NLS-1$
+ String flatten = fs[i].getString("exploded"); //$NON-NLS-1$
+ String flatten2 = flatten == null ? "" : flatten; //$NON-NLS-1$
+ boolean explodedValid = ("true".equals(flatten2.toLowerCase()) ||
"false".equals(flatten2.toLowerCase())); //$NON-NLS-1$ //$NON-NLS-2$
+ boolean inWorkspaceValid = ("true".equals(inWorkspace2.toLowerCase()) ||
"false".equals(inWorkspace2.toLowerCase())); //$NON-NLS-1$ //$NON-NLS-2$
+ boolean bFlat = explodedValid ? Boolean.parseBoolean(flatten) : false;
+ boolean bInWorkspace = inWorkspaceValid ? Boolean.parseBoolean(inWorkspace) : true;
+ fileset.setDir(dir);
+ fileset.setIncludes(inc);
+ if( exc != null && !"".equals(exc)) //$NON-NLS-1$
+ fileset.setExcludes(exc);
+ fileset.setInWorkspace(bInWorkspace);
+ fileset.setFlatten(bFlat);
- public static class XbException extends Exception {
- private Exception parent;
- public XbException(Exception e) {
- super();
- parent = e;
+ if( dir == null )
+ throw new XbException(new Exception("Element 'fileset' missing required
attribute 'dir'")); //$NON-NLS-1$
+ if( inc == null )
+ throw new XbException(new Exception("Element 'fileset' missing required
attribute 'includes'")); //$NON-NLS-1$
+
+ node.addChild(fileset);
}
- public Exception getException() {
- return parent;
+ }
+ private static void unmarshallLibFilesets(XbPackageNodeWithProperties node, IMemento[]
fs) {
+ for( int i = 0; i < fs.length; i++ ) {
+ XbLibFileSet fileset = new XbLibFileSet();
+ String id = fs[i].getString("id"); //$NON-NLS-1$
+ fileset.setId(id);
+ node.addChild(fileset);
}
- public String getMessage() {
- return parent.getCause() == null ? parent.getMessage() :
parent.getCause().getMessage();
+
+ }
+ private static void unmarshallProperties(XbPackageNodeWithProperties node, IMemento
propNode) throws XbException {
+ XbProperties propsWrapper = new XbProperties();
+ node.addChild(propsWrapper);
+ String[] names = ((XMLMemento)propNode).getChildNames();
+ Set<String> set = new TreeSet<String>();
+ set.addAll(Arrays.asList(names));
+ if( set.size() == 0 )
+ return; // no error, no props set
+ if( set.size() > 1 || !set.iterator().next().equals("property"))
//$NON-NLS-1$
+ throw new XbException(new Exception("Element 'property' contains unknown
attribute " + set.iterator().next())); //$NON-NLS-1$
+ IMemento[] allProps = propNode.getChildren("property"); //$NON-NLS-1$
+ for( int i = 0; i < allProps.length; i++ ) {
+ XbProperty p = new XbProperty();
+ String name = allProps[i].getString("name"); //$NON-NLS-1$
+ String val = allProps[i].getString("value"); //$NON-NLS-1$
+ if( name == null )
+ throw new XbException(new Exception("Element 'property' missing required
attribute 'name'")); //$NON-NLS-1$
+ if( val == null )
+ throw new XbException(new Exception("Element 'property' missing required
attribute 'value'")); //$NON-NLS-1$
+ if( allProps[i].getNames().size() > 2 )
+ throw new XbException(new Exception("Element 'property' contains unknown
attribute key")); //$NON-NLS-1$
+ p.setName(name);
+ p.setValue(val);
+ propsWrapper.addChild(p);
}
- public Throwable getCause() {
- return parent;
- }
}
}
Added:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLMemento.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLMemento.java
(rev 0)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLMemento.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -0,0 +1,440 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Jeff Mesnil
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.jboss.ide.eclipse.archives.core.model.internal.xb;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.xerces.dom.DocumentImpl;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
+
+/**
+ * Stolen from webtools wst.server.core
+ *
+ */
+public final class XMLMemento implements IMemento {
+ private Document factory;
+ private Element element;
+
+ /**
+ * Answer a memento for the document and element. For simplicity
+ * you should use createReadRoot and createWriteRoot to create the initial
+ * mementos on a document.
+ */
+ public XMLMemento(Document doc, Element el) {
+ factory = doc;
+ element = el;
+ }
+
+ /*
+ * @see IMemento
+ */
+ public IMemento createChild(String type) {
+ Element child = factory.createElement(type);
+ element.appendChild(child);
+ return new XMLMemento(factory, child);
+ }
+
+ public void removeChild(XMLMemento child) {
+ element.removeChild(child.element);
+ }
+
+ /**
+ * Create a Document from a Reader and answer a root memento for reading
+ * a document.
+ */
+ public static XMLMemento createReadRoot(InputStream in) {
+ Document document = null;
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setIgnoringComments(true);
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ document = parser.parse(new InputSource(in));
+ Node node = document.getFirstChild();
+ if (node instanceof Element)
+ return new XMLMemento(document, (Element) node);
+ } catch (Exception e) {
+ e.printStackTrace();
+ // ignore
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Answer a root memento for writing a document.
+ *
+ * @param type a type
+ * @return a memento
+ */
+ public static XMLMemento createWriteRoot(String type) {
+ Document document;
+ try {
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+
+ // THIS IS DIFFERENT THAN OTHER VERSIONS OF XMLMEMENTO
+ ((DocumentImpl)document).setXmlStandalone(true);
+ Element element = document.createElement(type);
+ document.appendChild(element);
+ return new XMLMemento(document, element);
+ } catch (ParserConfigurationException e) {
+ throw new Error(e);
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public IMemento getChild(String type) {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return null;
+
+ // Find the first node which is a child of this node.
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (element2.getNodeName().equals(type))
+ return new XMLMemento(factory, element2);
+ }
+ }
+
+ // A child was not found.
+ return null;
+ }
+
+ /*
+ * @see IMemento
+ */
+ public IMemento [] getChildren(String type) {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return new IMemento[0];
+
+ // Extract each node with given type.
+ List<Element> list = new ArrayList<Element>(size);
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (element2.getNodeName().equals(type))
+ list.add(element2);
+ }
+ }
+
+ // Create a memento for each node.
+ size = list.size();
+ IMemento [] results = new IMemento[size];
+ for (int x = 0; x < size; x ++) {
+ results[x] = new XMLMemento(factory, list.get(x));
+ }
+ return results;
+ }
+
+ public String[] getChildNames() {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return new String[0];
+
+ // Extract each node with given type.
+ List<String> list = new ArrayList<String>();
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (!list.contains(element2.getNodeName()))
+ list.add(element2.getNodeName());
+ }
+ }
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+
+ /**
+ * Return the contents of this memento as a byte array.
+ *
+ * @return byte[]
+ * @throws IOException if anything goes wrong
+ */
+ public byte[] getContents() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return out.toByteArray();
+ }
+
+ /**
+ * Returns an input stream for writing to the disk with a local locale.
+ *
+ * @return java.io.InputStream
+ * @throws IOException if anything goes wrong
+ */
+ public InputStream getInputStream() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return new ByteArrayInputStream(out.toByteArray());
+ }
+
+ /*
+ * @see IMemento
+ */
+ public Float getFloat(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ try {
+ return new Float(strValue);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public Integer getInteger(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ try {
+ return new Integer(strValue);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public String getString(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ return attr.getValue();
+ }
+
+ public List<String> getNames() {
+ NamedNodeMap map = element.getAttributes();
+ int size = map.getLength();
+ List<String> list = new ArrayList<String>();
+ for (int i = 0; i < size; i++) {
+ Node node = map.item(i);
+ String name = node.getNodeName();
+ list.add(name);
+ }
+ return list;
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param in java.io.InputStream
+ * @return org.eclipse.ui.IMemento
+ */
+ public static IMemento loadMemento(InputStream in) {
+ return createReadRoot(in);
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param filename java.lang.String
+ * @return org.eclipse.ui.IMemento
+ * @exception java.io.IOException
+ */
+ public static IMemento loadMemento(String filename) throws IOException {
+ InputStream in = null;
+ try {
+ in = new BufferedInputStream(new FileInputStream(filename));
+ return XMLMemento.createReadRoot(in);
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public void putInteger(String key, int n) {
+ element.setAttribute(key, String.valueOf(n));
+ }
+
+ /*
+ * @see IMemento
+ */
+ public void putString(String key, String value) {
+ if (value == null)
+ return;
+ element.setAttribute(key, value);
+ }
+
+ /**
+ * Save this Memento to a Writer.
+ *
+ * @throws IOException if there is a problem saving
+ */
+ public void save(OutputStream os) throws IOException {
+ Result result = new StreamResult(os);
+ Source source = new DOMSource(factory);
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
+
+ // This is different from other XMLMemento Copies!!!
+ //transformer.setOutputProperty(OutputKeys.STANDALONE, null);
+
+
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-a...;,
"2"); //$NON-NLS-1$ //$NON-NLS-2$
+ transformer.transform(source, result);
+ } catch (Exception e) {
+ throw (IOException) (new IOException().initCause(e));
+ }
+ }
+
+ /**
+ * Saves the memento to the given file.
+ *
+ * @param filename java.lang.String
+ * @exception java.io.IOException
+ */
+ public void saveToFile(String filename) throws IOException {
+ BufferedOutputStream w = null;
+ try {
+ w = new BufferedOutputStream(new FileOutputStream(filename));
+ save(w);
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IOException(e.getLocalizedMessage());
+ } finally {
+ if (w != null) {
+ try {
+ w.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ public String saveToString() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return out.toString("UTF-8"); //$NON-NLS-1$
+ }
+
+ /*
+ * @see IMemento#getBoolean(String)
+ */
+ public Boolean getBoolean(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ if ("true".equalsIgnoreCase(strValue)) //$NON-NLS-1$
+ return new Boolean(true);
+ return new Boolean(false);
+ }
+
+ /*
+ * @see IMemento#putBoolean(String, boolean)
+ */
+ public void putBoolean(String key, boolean value) {
+ element.setAttribute(key, new Boolean(value).toString());
+ }
+
+ /**
+ * Returns the Text node of the memento. Each memento is allowed only
+ * one Text node.
+ *
+ * @return the Text node of the memento, or <code>null</code> if
+ * the memento has no Text node.
+ */
+ public Text getTextNode() {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0) {
+ return null;
+ }
+ for (int nX = 0; nX < size; nX++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Text) {
+ return (Text) node;
+ }
+ }
+ // a Text node was not found
+ return null;
+ }
+
+ /* (non-Javadoc)
+ */
+ public void putTextData(String data) {
+ Text textNode = getTextNode();
+ if (textNode == null) {
+ textNode = factory.createTextNode(data);
+ // Always add the text node as the first child (fixes bug 93718)
+ element.insertBefore(textNode, element.getFirstChild());
+ } else {
+ textNode.setData(data);
+ }
+ }
+
+ public String getTextData() {
+ Text textNode = getTextNode();
+ if (textNode != null) {
+ return textNode.getData();
+ }
+ return ""; //$NON-NLS-1$
+ }
+}
\ No newline at end of file
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XbPackagesObjectProvider.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XbPackagesObjectProvider.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XbPackagesObjectProvider.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -10,8 +10,6 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.core.model.internal.xb;
-import org.jboss.xb.binding.GenericObjectModelProvider;
-import org.jboss.xb.binding.MarshallingContext;
/**
@@ -19,110 +17,111 @@
* @author Marshall
* @author Rob Stryker
*/
-public class XbPackagesObjectProvider implements GenericObjectModelProvider {
-
- public Object getRoot(Object o, MarshallingContext context, String namespaceURI, String
localName) {
- return o;
- }
-
- protected Object getNodeChildren(XbPackageNode node, String name) {
- if ("package".equals(name)) { //$NON-NLS-1$
- return node.getChildren(XbPackage.class);
- }
- else if ("folder".equals(name)) {//$NON-NLS-1$
- return node.getChildren(XbFolder.class);
- }
- else if ("fileset".equals(name)) {//$NON-NLS-1$
- return node.getChildren(XbFileSet.class);
- }
- else if( "lib-fileset".equals(name)) {//$NON-NLS-1$
- return node.getChildren(XbLibFileSet.class);
- }
- else if ("properties".equals(name) && node instanceof
XbPackageNodeWithProperties) {//$NON-NLS-1$
- return ((XbPackageNodeWithProperties)node).getProperties();
- }
- else if ("property".equals(name) && node instanceof XbProperties)
{//$NON-NLS-1$
- return ((XbProperties)node).getProperties().getPropertyElements();
- }
- else if( "buildAction".equals(name) && node instanceof XbPackage)
{//$NON-NLS-1$
- return ((XbPackage)node).getActions();
- }
-
- return null;
- }
-
- public Object getChildren(Object object, MarshallingContext context,
- String namespaceURI, String localName) {
- if (object instanceof XbPackageNode) {
- Object ret = getNodeChildren(((XbPackageNode)object), localName);
- return ret;
- }
- return null;
- }
-
-
- public Object getAttributeValue(Object object, MarshallingContext context,
- String namespaceURI, String localName) {
- if( object instanceof XbPackages ) {
- if("version".equals(localName))//$NON-NLS-1$
- return ((XbPackages)object).getVersion();
- }
- else if (object instanceof XbPackage) {
- XbPackage pkg = (XbPackage)object;
- if("id".equals(localName))//$NON-NLS-1$
- return pkg.getId();
- else if ("type".equals(localName))//$NON-NLS-1$
- return pkg.getPackageType();
- else if ("name".equals(localName))//$NON-NLS-1$
- return pkg.getName();
- else if ("exploded".equals(localName))//$NON-NLS-1$
- return Boolean.valueOf(pkg.isExploded());
- else if ("todir".equals(localName))//$NON-NLS-1$
- return pkg.getToDir();
- else if ("inWorkspace".equals(localName))//$NON-NLS-1$
- return ""+pkg.isInWorkspace();//$NON-NLS-1$
- }
- else if (object instanceof XbFolder) {
- XbFolder folder = (XbFolder) object;
- if ("name".equals(localName))//$NON-NLS-1$
- return folder.getName();
- }
- else if (object instanceof XbFileSet) {
- XbFileSet fileset = (XbFileSet)object;
- if ("dir".equals(localName))//$NON-NLS-1$
- return fileset.getDir();
- else if ("includes".equals(localName))//$NON-NLS-1$
- return fileset.getIncludes();
- else if ("excludes".equals(localName))//$NON-NLS-1$
- return fileset.getExcludes();
- else if ("inWorkspace".equals(localName))//$NON-NLS-1$
- return "" + fileset.isInWorkspace();//$NON-NLS-1$
- else if("flatten".equals(localName))//$NON-NLS-1$
- return new Boolean(fileset.isFlattened()).toString();
- }
- else if( object instanceof XbLibFileSet ) {
- XbLibFileSet fs = (XbLibFileSet)object;
- if( "id".equals(localName)) //$NON-NLS-1$
- return fs.getId();
- }
- else if (object instanceof XbProperty) {
- XbProperty prop = (XbProperty) object;
- if ("name".equals(localName))//$NON-NLS-1$
- return prop.getName();
- else if ("value".equals(localName))//$NON-NLS-1$
- return prop.getValue();
- } else if( object instanceof XbAction ) {
- XbAction action = (XbAction)object;
- if("time".equals(localName))//$NON-NLS-1$
- return action.getTime();
- if("type".equals(localName))//$NON-NLS-1$
- return action.getType();
- }
- return null;
- }
-
- // do not care ;)
- public Object getElementValue(Object object, MarshallingContext context, String
namespaceURI, String localName) {
- return null;
- }
+public class XbPackagesObjectProvider {
+//implements GenericObjectModelProvider {
+//
+// public Object getRoot(Object o, MarshallingContext context, String namespaceURI,
String localName) {
+// return o;
+// }
+//
+// protected Object getNodeChildren(XbPackageNode node, String name) {
+// if ("package".equals(name)) { //$NON-NLS-1$
+// return node.getChildren(XbPackage.class);
+// }
+// else if ("folder".equals(name)) {//$NON-NLS-1$
+// return node.getChildren(XbFolder.class);
+// }
+// else if ("fileset".equals(name)) {//$NON-NLS-1$
+// return node.getChildren(XbFileSet.class);
+// }
+// else if( "lib-fileset".equals(name)) {//$NON-NLS-1$
+// return node.getChildren(XbLibFileSet.class);
+// }
+// else if ("properties".equals(name) && node instanceof
XbPackageNodeWithProperties) {//$NON-NLS-1$
+// return ((XbPackageNodeWithProperties)node).getProperties();
+// }
+// else if ("property".equals(name) && node instanceof XbProperties)
{//$NON-NLS-1$
+// return ((XbProperties)node).getProperties().getPropertyElements();
+// }
+// else if( "buildAction".equals(name) && node instanceof XbPackage)
{//$NON-NLS-1$
+// return ((XbPackage)node).getActions();
+// }
+//
+// return null;
+// }
+//
+// public Object getChildren(Object object, MarshallingContext context,
+// String namespaceURI, String localName) {
+// if (object instanceof XbPackageNode) {
+// Object ret = getNodeChildren(((XbPackageNode)object), localName);
+// return ret;
+// }
+// return null;
+// }
+//
+//
+// public Object getAttributeValue(Object object, MarshallingContext context,
+// String namespaceURI, String localName) {
+// if( object instanceof XbPackages ) {
+// if("version".equals(localName))//$NON-NLS-1$
+// return ((XbPackages)object).getVersion();
+// }
+// else if (object instanceof XbPackage) {
+// XbPackage pkg = (XbPackage)object;
+// if("id".equals(localName))//$NON-NLS-1$
+// return pkg.getId();
+// else if ("type".equals(localName))//$NON-NLS-1$
+// return pkg.getPackageType();
+// else if ("name".equals(localName))//$NON-NLS-1$
+// return pkg.getName();
+// else if ("exploded".equals(localName))//$NON-NLS-1$
+// return Boolean.valueOf(pkg.isExploded());
+// else if ("todir".equals(localName))//$NON-NLS-1$
+// return pkg.getToDir();
+// else if ("inWorkspace".equals(localName))//$NON-NLS-1$
+// return ""+pkg.isInWorkspace();//$NON-NLS-1$
+// }
+// else if (object instanceof XbFolder) {
+// XbFolder folder = (XbFolder) object;
+// if ("name".equals(localName))//$NON-NLS-1$
+// return folder.getName();
+// }
+// else if (object instanceof XbFileSet) {
+// XbFileSet fileset = (XbFileSet)object;
+// if ("dir".equals(localName))//$NON-NLS-1$
+// return fileset.getDir();
+// else if ("includes".equals(localName))//$NON-NLS-1$
+// return fileset.getIncludes();
+// else if ("excludes".equals(localName))//$NON-NLS-1$
+// return fileset.getExcludes();
+// else if ("inWorkspace".equals(localName))//$NON-NLS-1$
+// return "" + fileset.isInWorkspace();//$NON-NLS-1$
+// else if("flatten".equals(localName))//$NON-NLS-1$
+// return new Boolean(fileset.isFlattened()).toString();
+// }
+// else if( object instanceof XbLibFileSet ) {
+// XbLibFileSet fs = (XbLibFileSet)object;
+// if( "id".equals(localName)) //$NON-NLS-1$
+// return fs.getId();
+// }
+// else if (object instanceof XbProperty) {
+// XbProperty prop = (XbProperty) object;
+// if ("name".equals(localName))//$NON-NLS-1$
+// return prop.getName();
+// else if ("value".equals(localName))//$NON-NLS-1$
+// return prop.getValue();
+// } else if( object instanceof XbAction ) {
+// XbAction action = (XbAction)object;
+// if("time".equals(localName))//$NON-NLS-1$
+// return action.getTime();
+// if("type".equals(localName))//$NON-NLS-1$
+// return action.getType();
+// }
+// return null;
+// }
+//
+// // do not care ;)
+// public Object getElementValue(Object object, MarshallingContext context, String
namespaceURI, String localName) {
+// return null;
+// }
}
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -201,6 +201,8 @@
}
public static void fillArchiveModel( XbPackages node, IArchiveModelRootNode modelNode)
throws ArchivesModelException {
+ if( node == null )
+ return;
for (Iterator iter = node.getAllChildren().iterator(); iter.hasNext(); ) {
XbPackageNode child = (XbPackageNode) iter.next();
ArchiveNodeImpl childImpl = (ArchiveNodeImpl)createPackageNodeImpl(child, modelNode);
Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd 2012-07-25
04:56:48 UTC (rev 42698)
@@ -139,6 +139,7 @@
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="package" type="package-type"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="fileset" type="fileset-type"/>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="lib-fileset" type="lib-fileset-type"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="folder" type="folder-type"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="properties" type="properties-type"/>
</xsd:sequence>
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/expectedOutputs/emptyPackages.xml
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/expectedOutputs/emptyPackages.xml 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/expectedOutputs/emptyPackages.xml 2012-07-25
04:56:48 UTC (rev 42698)
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
-
<packages version="0.0">
- <properties></properties>
-</packages>
\ No newline at end of file
+ <properties/>
+</packages>
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/validation/MissingFilesetDir.xml
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/validation/MissingFilesetDir.xml 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/validation/MissingFilesetDir.xml 2012-07-25
04:56:48 UTC (rev 42698)
@@ -2,7 +2,7 @@
<packages>
<package name="TestProject.jar" type="jar"
todir="/some/external/path" exploded="false"
inWorkspace="false" id="someId">
- <fileset dir="/some/global/path" includes="**/*.xml"
inWorkspace="false" excludes="" flattened="false">
+ <fileset includes="**/*.xml" inWorkspace="false"
excludes="" flattened="false">
<properties></properties>
</fileset>
</package>
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -18,7 +18,6 @@
import junit.framework.TestCase;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -21,13 +21,13 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbAction;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFolder;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbProperty;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
import org.jboss.ide.eclipse.archives.test.ArchivesTest;
import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
import org.osgi.framework.Bundle;
@@ -225,15 +225,20 @@
write(packs, shouldSucceed);
}
- public void testWriteActionSuccess() {
- writeAction("preBuild", "ant", true);
- }
- public void testWriteActionMissingTime() {
- writeAction(null, "ant", false);
- }
-
- public void testWriteActionMissingType() {
- writeAction("preBuild", null, false);
- }
+ /*
+ * "ACTIONS" were never fully added. There is no UI to use them, and never has
been.
+ * Testing them does not make sense at this time.
+ */
+// public void testWriteActionSuccess() {
+// writeAction("preBuild", "ant", true);
+// }
+//
+// public void testWriteActionMissingTime() {
+// writeAction(null, "ant", false);
+// }
+//
+// public void testWriteActionMissingType() {
+// writeAction("preBuild", null, false);
+// }
}
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.test.model;
-import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.List;
@@ -22,10 +21,10 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
import org.jboss.ide.eclipse.archives.test.ArchivesTest;
import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
import org.osgi.framework.Bundle;
@@ -79,11 +78,6 @@
public void testPackageMissingPackageName() {
parse("MissingPackageName.xml", false,
failedMissingRequiredAtt("name"));
}
-
- // Currently the schema is written that this will pass
-// public void testPackageMissingDirectory() {
-// parse("MissingPackageDir.xml", false,
failedMissingRequiredAtt("todir"));
-// }
public void testPackageMissingOptionalType() {
parse("MissingPackageType.xml", true,
failedFalsePositiveRequiredAtt("type"));
@@ -167,19 +161,23 @@
assertFalse(fs.isFlattened());
}
+ /*
+ * Actions have never been implemented with any UI or true functionality
+ * and have only been here as a possible future feature.
+ */
- public void testCorrectAction() {
- parse("CorrectAction.xml", true,
shouldParse("CorrectAction.xml"));
- }
+// public void testCorrectAction() {
+// parse("CorrectAction.xml", true,
shouldParse("CorrectAction.xml"));
+// }
+//
+// public void testActionMissingTime() {
+// parse("MissingActionTime.xml", false,
failedMissingRequiredAtt("time"));
+// }
+//
+// public void testActionMissingType() {
+// parse("MissingActionType.xml", false,
failedMissingRequiredAtt("type"));
+// }
- public void testActionMissingTime() {
- parse("MissingActionTime.xml", false,
failedMissingRequiredAtt("time"));
- }
-
- public void testActionMissingType() {
- parse("MissingActionType.xml", false,
failedMissingRequiredAtt("type"));
- }
-
public void testReadPackagesVersion() {
XbPackages packs = parse("ReadVersion.xml", true,
failedFalsePositiveRequiredAtt("exploded"));
assertEquals(new Float(packs.getVersion()), new Float(1.2));
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/projects/JBIDE2439Test.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/projects/JBIDE2439Test.java 2012-07-24
23:21:29 UTC (rev 42697)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/projects/JBIDE2439Test.java 2012-07-25
04:56:48 UTC (rev 42698)
@@ -25,6 +25,7 @@
import org.eclipse.core.runtime.Path;
import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
import org.jboss.ide.eclipse.archives.test.ArchivesTest;
+import org.jboss.tools.test.util.JobUtils;
import org.jboss.tools.test.util.ResourcesUtils;
public class JBIDE2439Test extends TestCase {
@@ -60,6 +61,7 @@
try {
delegate.fullProjectBuild(aProject.getLocation(), new NullProgressMonitor());
aProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ JobUtils.waitForIdle(1000);
IResource outs = aProject.getFolder("outputs");
final ArrayList<IResource> list = new ArrayList<IResource>();
outs.accept(new IResourceVisitor() {