JBoss Tools SVN: r42701 - trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2012-07-25 03:50:11 -0400 (Wed, 25 Jul 2012)
New Revision: 42701
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java
Log:
missed commit /JBIDE-12229
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java 2012-07-25 05:28:29 UTC (rev 42700)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java 2012-07-25 07:50:11 UTC (rev 42701)
@@ -41,8 +41,7 @@
private static File getLinuxServerLibFolder(String version, IVMInstall install) {
File serverFolder = null;
IPath locPath = new Path(install.getInstallLocation().getAbsolutePath());
- if( version.startsWith("1.7.")) //$NON-NLS-1$
- serverFolder = findServerFolder(locPath.append("jre").append("lib")); //$NON-NLS-1$ //$NON-NLS-2$
+ serverFolder = findServerFolder(locPath.append("jre").append("lib")); //$NON-NLS-1$ //$NON-NLS-2$
return serverFolder;
}
13 years, 5 months
JBoss Tools SVN: r42700 - branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2012-07-25 01:28:29 -0400 (Wed, 25 Jul 2012)
New Revision: 42700
Modified:
branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java
Log:
JBIDE-12229 small update to fix jdk < 1.7 on linux
Modified: branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java
===================================================================
--- branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java 2012-07-25 05:04:53 UTC (rev 42699)
+++ branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JavaUtils.java 2012-07-25 05:28:29 UTC (rev 42700)
@@ -41,8 +41,7 @@
private static File getLinuxServerLibFolder(String version, IVMInstall install) {
File serverFolder = null;
IPath locPath = new Path(install.getInstallLocation().getAbsolutePath());
- if( version.startsWith("1.7.")) //$NON-NLS-1$
- serverFolder = findServerFolder(locPath.append("jre").append("lib")); //$NON-NLS-1$ //$NON-NLS-2$
+ serverFolder = findServerFolder(locPath.append("jre").append("lib")); //$NON-NLS-1$ //$NON-NLS-2$
return serverFolder;
}
13 years, 5 months
JBoss Tools SVN: r42699 - in trunk/archives/plugins/org.jboss.ide.eclipse.archives.core: src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2012-07-25 01:04:53 -0400 (Wed, 25 Jul 2012)
New Revision: 42699
Removed:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/concurrent-1.3.4.jar
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-common-core-2.2.1.GA.jar
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-common-logging-log4j-2.0.4.GA.jar
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-common-logging-spi-2.0.4.GA.jar
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-xml-binding.jar
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/xercesImpl-2.9.1.jar
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/XbPackagesObjectProvider.java
Log:
JBIDE-12336 to trunk commit 2 - removal of unnecessary classes and libs. Cleanup.
Deleted: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/concurrent-1.3.4.jar
===================================================================
(Binary files differ)
Deleted: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-common-core-2.2.1.GA.jar
===================================================================
(Binary files differ)
Deleted: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-common-logging-log4j-2.0.4.GA.jar
===================================================================
(Binary files differ)
Deleted: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-common-logging-spi-2.0.4.GA.jar
===================================================================
(Binary files differ)
Deleted: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/jboss-xml-binding.jar
===================================================================
(Binary files differ)
Deleted: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/lib/xercesImpl-2.9.1.jar
===================================================================
(Binary files differ)
Deleted: 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-25 04:56:48 UTC (rev 42698)
+++ 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 05:04:53 UTC (rev 42699)
@@ -1,188 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.core.model.internal.xb;
-
-
-/**
- * Unmarshaller implementation.
- * WARNING: this implementation is not thread-safe.
- *
- * Taken from JBoss XB. Changed to let getParser() be public.
- *
- * @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;
-// }
-}
Deleted: 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-25 04:56:48 UTC (rev 42698)
+++ 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 05:04:53 UTC (rev 42699)
@@ -1,1411 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.core.model.internal.xb;
-
-
-/**
- * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
- * @version <tt>$Revision: 1958 $</tt>
- */
-public class StrictXercesXSMarshaller
-// 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);
-// }
-// };
-// }
-}
Deleted: 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-25 04:56:48 UTC (rev 42698)
+++ 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 05:04:53 UTC (rev 42699)
@@ -1,127 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.core.model.internal.xb;
-
-
-
-/**
- * Necessary class for JBoss XB
- * @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;
-// }
-}
13 years, 5 months
JBoss Tools SVN: r42698 - in trunk/archives: plugins/org.jboss.ide.eclipse.archives.core/META-INF and 11 other directories.
by jbosstools-commits@lists.jboss.org
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/validation/schema", true); //$NON-NLS-1$
- unmarshaller.getParser().setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", 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-amount", "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() {
13 years, 5 months
JBoss Tools SVN: r42697 - trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2012-07-24 19:21:29 -0400 (Tue, 24 Jul 2012)
New Revision: 42697
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java
Log:
Removed unused messages
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java 2012-07-24 21:35:23 UTC (rev 42696)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java 2012-07-24 23:21:29 UTC (rev 42697)
@@ -25,16 +25,8 @@
public static String ELInfoHover_noAttachedJavaSource; //
public static String ELInfoHover_noInformation; //
public static String ELInfoHover_error_gettingJavadoc; //
- public static String ELInfoHover_baseName;
- public static String ELInfoHover_propertyName;
- public static String ELInfoHover_resourceBundle;
- public static String ELInfoHover_resourceBundlePropertyValue;
- public static String ELInfoHover_resourceBundlePropertyValueNotDefined;
- public static String ELInfoHover_resourceBundleNotDefined;
- public static String ELInfoHover_newLine;
- public static String ELInfoHover_treeDots;
-
+
static {
NLS.initializeMessages(BUNDLE_NAME, ELInfoHoverMessages.class);
}
-}
+}
\ No newline at end of file
13 years, 5 months
JBoss Tools SVN: r42696 - in trunk: cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: dazarov
Date: 2012-07-24 17:35:23 -0400 (Tue, 24 Jul 2012)
New Revision: 42696
Added:
trunk/seam/plugins/org.jboss.tools.seam.xml.ui/images/seam_components_file.png
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/AssignableBeansDialog.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/OpenCDINamedBeanDialog.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/HierarchyInformationControl.java
Log:
Black font on black background in some dialogs https://issues.jboss.org/browse/JBIDE-12350
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/AssignableBeansDialog.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/AssignableBeansDialog.java 2012-07-24 19:12:37 UTC (rev 42695)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/AssignableBeansDialog.java 2012-07-24 21:35:23 UTC (rev 42696)
@@ -585,7 +585,7 @@
}
static Color gray = new Color(null, 128, 128, 128);
- static Color black = new Color(null, 0, 0, 0);
+ static Color black = Display.getDefault().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
static Styler RESOLVED_NAME = new DefaultStyler(black, true, false);
static Styler ELIGIBLE_NAME = new DefaultStyler(black, false, false);
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/OpenCDINamedBeanDialog.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/OpenCDINamedBeanDialog.java 2012-07-24 19:12:37 UTC (rev 42695)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/OpenCDINamedBeanDialog.java 2012-07-24 21:35:23 UTC (rev 42696)
@@ -34,6 +34,7 @@
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.StyledString.Styler;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.TextStyle;
@@ -377,7 +378,7 @@
public class CDINamedBeanLabelProvider implements IStyledLabelProvider, ILabelProvider {
final Color gray = new Color(null, 128, 128, 128);
- final Color black = new Color(null, 0, 0, 0);
+ final Color black = getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
final Styler NAME_STYLE = new CDIBeanStyler(black);
final Styler QUALIFIED_NAME_STYLE = new CDIBeanStyler(gray);
Modified: trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/HierarchyInformationControl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/HierarchyInformationControl.java 2012-07-24 19:12:37 UTC (rev 42695)
+++ trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/HierarchyInformationControl.java 2012-07-24 21:35:23 UTC (rev 42696)
@@ -29,6 +29,7 @@
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.dialogs.SearchPattern;
@@ -154,7 +155,7 @@
}
protected static Color gray = new Color(null, 128, 128, 128);
- protected static Color black = new Color(null, 0, 0, 0);
+ protected static Color black = Display.getDefault().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
protected static Styler NAME_STYLE = new DefaultStyler(black, false);
protected static Styler PACKAGE_STYLE = new DefaultStyler(gray, false);
Added: trunk/seam/plugins/org.jboss.tools.seam.xml.ui/images/seam_components_file.png
===================================================================
(Binary files differ)
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.xml.ui/images/seam_components_file.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
13 years, 5 months
JBoss Tools SVN: r42695 - trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2012-07-24 15:12:37 -0400 (Tue, 24 Jul 2012)
New Revision: 42695
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java
Log:
https://issues.jboss.org/browse/JBIDE-12367 NPE in JavaStringELInfoHover
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java 2012-07-24 16:47:41 UTC (rev 42694)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java 2012-07-24 19:12:37 UTC (rev 42695)
@@ -258,7 +258,7 @@
continue;
ELSegment segment = resolution.getLastSegment();
- if (!segment.isResolved()) continue;
+ if (segment==null || !segment.isResolved()) continue;
if(segment instanceof JavaMemberELSegmentImpl) {
JavaMemberELSegmentImpl jmSegment = (JavaMemberELSegmentImpl)segment;
13 years, 5 months
JBoss Tools SVN: r42694 - in trunk/maven/plugins: org.jboss.tools.maven.conversion.ui and 13 other directories.
by jbosstools-commits@lists.jboss.org
Author: fbricon
Date: 2012-07-24 12:47:41 -0400 (Tue, 24 Jul 2012)
New Revision: 42694
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.classpath
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.gitignore
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.project
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.jdt.core.prefs
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.m2e.core.prefs
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/build.properties
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/error_st_obj.gif
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/find_obj.gif
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/jar_obj.gif
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/loader.gif
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/passed.png
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/projects.gif
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.properties
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/pom.xml
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/Messages.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConversionUtils.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/EditDependencyDialog.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/GenericCommandActionDelegate.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/MavenDependencyConversionActivator.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/messages.properties
Modified:
trunk/maven/plugins/pom.xml
Log:
JBIDE-8973 : initial jar conversion plugin import
Property changes on: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui
___________________________________________________________________
Added: svn:ignore
+ target
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.classpath
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.classpath (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.classpath 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.gitignore
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.gitignore (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.gitignore 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,2 @@
+/target
+/bin
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.project
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.project (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.project 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.maven.conversion.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.jdt.core.prefs 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.m2e.core.prefs
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.m2e.core.prefs (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/.settings/org.eclipse.m2e.core.prefs 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %BundleName
+Bundle-SymbolicName: org.jboss.tools.maven.conversion.ui;singleton:=true
+Bundle-Version: 1.4.0.qualifier
+Bundle-Activator: org.jboss.tools.maven.conversion.ui.internal.MavenDependencyConversionActivator
+Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
+ org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.jdt.core;bundle-version="3.7.0",
+ org.eclipse.jdt.ui;bundle-version="3.7.0",
+ org.eclipse.core.variables;bundle-version="3.2.500",
+ org.eclipse.core.resources,
+ org.eclipse.jst.j2ee.ui;bundle-version="1.1.500",
+ org.eclipse.ui.ide;bundle-version="3.7.0",
+ org.jboss.tools.maven.sourcelookup.core;bundle-version="1.4.0",
+ org.eclipse.m2e.core.ui;bundle-version="1.1.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Vendor: %BundleVendor
+Bundle-Localization: plugin
+Export-Package: org.jboss.tools.maven.conversion.ui,
+ org.jboss.tools.maven.conversion.ui.dialog,
+ org.jboss.tools.maven.conversion.ui.handlers
+Bundle-ActivationPolicy: lazy
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/build.properties
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/build.properties (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/build.properties 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ icons/
+src.includes = src/
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/error_st_obj.gif
===================================================================
(Binary files differ)
Property changes on: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/error_st_obj.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/find_obj.gif
===================================================================
(Binary files differ)
Property changes on: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/find_obj.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/jar_obj.gif
===================================================================
(Binary files differ)
Property changes on: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/jar_obj.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/loader.gif
===================================================================
(Binary files differ)
Property changes on: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/loader.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/passed.png
===================================================================
(Binary files differ)
Property changes on: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/passed.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/projects.gif
===================================================================
(Binary files differ)
Property changes on: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/icons/projects.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.properties
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.properties (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.properties 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,3 @@
+#Properties file for org.jboss.tools.maven.conversion.ui
+BundleVendor = JBoss by Red Hat
+BundleName = JBoss Tools Maven Conversion UI
\ No newline at end of file
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.5"?>
+<plugin>
+ <extension point="org.eclipse.ui.commands">
+ <command
+ id="org.jboss.tools.maven.conversion.ui.commands.convertToMavenDependencies"
+ name="Convert to Maven Dependency..."
+ defaultHandler="org.jboss.tools.maven.conversion.ui.handlers.ConvertToMavenDependencyHandler"
+ >
+ </command>
+ </extension>
+ <extension point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.ui.popup.any?after=additions">
+
+ <command
+ commandId="org.jboss.tools.maven.conversion.ui.commands.convertToMavenDependencies"
+ style="push">
+ <visibleWhen>
+ <or>
+ <with variable="activeMenuSelection">
+ <iterate>
+ <or>
+ <adapt type="org.eclipse.jdt.internal.ui.packageview.ClassPathContainer" />
+ <adapt type="org.eclipse.jdt.core.IPackageFragmentRoot"/>
+ </or>
+ </iterate>
+ </with>
+ </or>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+
+
+ <extension
+ point="org.eclipse.m2e.core.projectConversionParticipants">
+ <projectConversionParticipant
+ class="org.jboss.tools.maven.conversion.ui.internal.ClasspathConversionParticipant"
+ id="org.jboss.tools.maven.conversion.ui.internal.ClasspathConversionParticipant"
+ name="Classpath conversion participant"
+ nature="org.eclipse.jdt.core.javanature">
+ </projectConversionParticipant>
+ </extension>
+</plugin>
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/pom.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/pom.xml (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/pom.xml 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.tools.maven</groupId>
+ <artifactId>plugins</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.jboss.tools.maven.plugins</groupId>
+ <artifactId>org.jboss.tools.maven.conversion.ui</artifactId>
+
+ <packaging>eclipse-plugin</packaging>
+</project>
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/Messages.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/Messages.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/Messages.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,44 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.conversion.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ * @author Fred Bricon
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.jboss.tools.maven.conversion.ui.messages"; //$NON-NLS-1$
+
+ public static String Convert_Maven_Dependency;
+
+ public static String Maven_Configuration_Warning;
+
+ public static String Maven_Configuration_Dialog_Warning;
+
+ public static String Jre_Warning;
+
+ public static String Jre_Dialog_Warning;
+
+ public static String Gradle_Configuration_Warning;
+
+ public static String Gradle_Configuration_Dialog_Warning;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConversionUtils.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConversionUtils.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConversionUtils.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Theodora Yeung (tyeung(a)bea.com) - ensure that JarPackageFragmentRoot make it into cache
+ * before its contents
+ * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422)
+ * Stephan Herrmann - Contribution for Bug 346010 - [model] strange initialization dependency in OptionTests
+ * Terry Parker <tparker(a)google.com> - DeltaProcessor misses state changes in archive files, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=357425
+ * Red Hat - copied code from {@link org.eclipse.jdt.internal.core.JavaModelManager.#getZipFile(IPath)}
+ *******************************************************************************/
+package org.jboss.tools.maven.conversion.ui.dialog;
+
+import java.io.File;
+import java.net.URI;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.internal.core.util.Messages;
+import org.eclipse.jdt.internal.core.util.Util;
+import org.jboss.tools.maven.conversion.ui.internal.MavenDependencyConversionActivator;
+
+@SuppressWarnings("restriction")
+public class ConversionUtils {
+
+
+ /**
+ * Returns the underlying {@link File} from a {@link IClasspathEntry}.
+ * <br/>
+ * Part of the code comes from {@link org.eclipse.jdt.internal.core.JavaModelManager.#getZipFile(IPath)}
+ * @param cpe
+ * @return
+ * @throws CoreException
+ */
+ public static File getFile(IClasspathEntry cpe) throws CoreException {
+ IPath path = cpe.getPath();
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource file = root.findMember(path);
+ File localFile = null;
+ if (file != null) {
+ // internal resource
+ URI location;
+ if (file.getType() != IResource.FILE || (location = file.getLocationURI()) == null) {
+ throw new CoreException(new Status(IStatus.ERROR, MavenDependencyConversionActivator.PLUGIN_ID, -1, Messages.bind(Messages.file_notFound, path.toString()), null));
+ }
+ localFile = Util.toLocalFile(location, null/*no progress availaible*/);
+ if (localFile == null)
+ throw new CoreException(new Status(IStatus.ERROR, MavenDependencyConversionActivator.PLUGIN_ID, -1, Messages.bind(Messages.file_notFound, path.toString()), null));
+ } else {
+ // external resource -> it is ok to use toFile()
+ localFile= path.toFile();
+ }
+ return localFile;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,56 @@
+package org.jboss.tools.maven.conversion.ui.dialog;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.model.Dependency;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jface.wizard.Wizard;
+
+public class ConvertToMavenDependencyWizard extends Wizard {
+
+ private IProject project;
+ private Set<IClasspathEntry> entries;
+
+
+ IdentifyMavenDependencyPage identificationPage;
+ private List<Dependency> dependencies;
+
+ public ConvertToMavenDependencyWizard(IProject project, Set<IClasspathEntry> entries) {
+ this.project = project;
+ this.entries = entries;
+ String title = "Convert to Maven ";
+ if (entries.size() > 1) {
+ title += "Dependencies";
+ } else {
+ title += "Dependency";
+ }
+ setWindowTitle(title);
+ }
+
+
+ @Override
+ public void addPages() {
+ identificationPage = new IdentifyMavenDependencyPage(project, entries);
+ addPage(identificationPage);
+ //DependencyConversionPreviewPage page2 = new DependencyConversionPreviewPage("Foo");
+ //addPage(page2);
+ }
+
+
+ @Override
+ public boolean performFinish() {
+ if (identificationPage != null) {
+ dependencies = identificationPage.getDependencies();
+ }
+ return true;
+ }
+
+
+ public List<Dependency> getDependencies() {
+ return dependencies;
+ }
+
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,47 @@
+package org.jboss.tools.maven.conversion.ui.dialog;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+public class DependencyConversionPreviewPage extends WizardPage {
+
+ private Button deleteJarsBtn;
+
+ private boolean deleteJars;
+
+ protected DependencyConversionPreviewPage(String pageName) {
+ super(pageName);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ container.setEnabled(true);
+ setControl(container);
+
+ deleteJarsBtn = addCheckButton(container, "Delete local project jars after conversion", deleteJars);
+
+ }
+
+ private Button addCheckButton(Composite container, String label,
+ boolean selected) {
+ Button checkBtn = new Button(container, SWT.CHECK);
+ checkBtn.setText(label);
+ checkBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
+ checkBtn.setSelection(selected);
+ return checkBtn;
+ }
+
+ @Override
+ public boolean isPageComplete() {
+ return false;
+ }
+
+ public boolean isDeleteJars() {
+ return deleteJars;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/EditDependencyDialog.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/EditDependencyDialog.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/EditDependencyDialog.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,231 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2011 Sonatype, Inc.
+ * 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
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.jboss.tools.maven.conversion.ui.dialog;
+
+import static org.eclipse.m2e.core.ui.internal.util.Util.nvl;
+
+import org.apache.maven.model.Dependency;
+import org.eclipse.m2e.core.ui.internal.Messages;
+import org.eclipse.m2e.core.ui.internal.util.M2EUIUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.SelectionStatusDialog;
+
+
+public class EditDependencyDialog extends SelectionStatusDialog {
+ private static final String[] TYPES = new String[] {"jar", "war", "rar", "ear", "par", "ejb", "ejb-client", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+ "test-jar", "java-source", "javadoc", "maven-plugin", "pom"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+
+ private String[] scopes = new String[] {"compile", "provided", "runtime", "test", "system"};
+
+ protected Text groupIdText;
+
+ protected Text artifactIdText;
+
+ protected Text versionText;
+
+ protected Text classifierText;
+
+ protected Combo typeCombo;
+
+ protected Combo scopeCombo;
+
+ protected Text systemPathText;
+
+ protected Button optionalButton;
+
+ private Dependency dependency;
+
+/**
+ *
+ * @param parent
+ * @param dependencyManagement
+ * @param project can be null, only used for indexer search as scope
+ * @param mavenProject
+ */
+ public EditDependencyDialog(Shell parent) {
+ super(parent);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ setTitle("Edit dependency");
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite superComposite = (Composite) super.createDialogArea(parent);
+
+ Composite composite = new Composite(superComposite, SWT.NONE);
+ composite.setLayout(new GridLayout(3, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Label groupIdLabel = new Label(composite, SWT.NONE);
+ groupIdLabel.setText(Messages.EditDependencyDialog_groupId_label);
+
+ groupIdText = new Text(composite, SWT.BORDER);
+ GridData gd_groupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
+ gd_groupIdText.horizontalIndent = 4;
+ groupIdText.setLayoutData(gd_groupIdText);
+ //ProposalUtil.addGroupIdProposal(project, groupIdText, Packaging.ALL);
+ M2EUIUtils.addRequiredDecoration(groupIdText);
+
+ Label artifactIdLabel = new Label(composite, SWT.NONE);
+ artifactIdLabel.setText("Artifact Id");
+
+ artifactIdText = new Text(composite, SWT.BORDER);
+ GridData gd_artifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
+ gd_artifactIdText.horizontalIndent = 4;
+ artifactIdText.setLayoutData(gd_artifactIdText);
+ //ProposalUtil.addArtifactIdProposal(project, groupIdText, artifactIdText, Packaging.ALL);
+ M2EUIUtils.addRequiredDecoration(artifactIdText);
+
+ Label versionLabel = new Label(composite, SWT.NONE);
+ versionLabel.setText(Messages.EditDependencyDialog_version_label);
+
+ versionText = new Text(composite, SWT.BORDER);
+ GridData versionTextData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
+ versionTextData.horizontalIndent = 4;
+ versionTextData.widthHint = 200;
+ versionText.setLayoutData(versionTextData);
+ //ProposalUtil.addVersionProposal(project, mavenproject, groupIdText, artifactIdText, versionText, Packaging.ALL);
+
+ Label classifierLabel = new Label(composite, SWT.NONE);
+ classifierLabel.setText(Messages.EditDependencyDialog_classifier_label);
+
+ classifierText = new Text(composite, SWT.BORDER);
+ GridData gd_classifierText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
+ gd_classifierText.horizontalIndent = 4;
+ gd_classifierText.widthHint = 200;
+ classifierText.setLayoutData(gd_classifierText);
+ //ProposalUtil
+ // .addClassifierProposal(project, groupIdText, artifactIdText, versionText, classifierText, Packaging.ALL);
+
+ Label typeLabel = new Label(composite, SWT.NONE);
+ typeLabel.setText(Messages.EditDependencyDialog_type_label);
+
+ typeCombo = new Combo(composite, SWT.NONE);
+ typeCombo.setItems(TYPES);
+ GridData gd_typeText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
+ gd_typeText.horizontalIndent = 4;
+ gd_typeText.widthHint = 120;
+ typeCombo.setLayoutData(gd_typeText);
+
+ Label scopeLabel = new Label(composite, SWT.NONE);
+ scopeLabel.setText(Messages.EditDependencyDialog_scope_label);
+
+ scopeCombo = new Combo(composite, SWT.NONE);
+ scopeCombo.setItems(scopes);
+ GridData gd_scopeText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
+ gd_scopeText.horizontalIndent = 4;
+ gd_scopeText.widthHint = 120;
+ scopeCombo.setLayoutData(gd_scopeText);
+
+ Label systemPathLabel = new Label(composite, SWT.NONE);
+ systemPathLabel.setText(Messages.EditDependencyDialog_systemPath_label);
+
+ systemPathText = new Text(composite, SWT.BORDER);
+ GridData gd_systemPathText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
+ gd_systemPathText.horizontalIndent = 4;
+ gd_systemPathText.widthHint = 200;
+ systemPathText.setLayoutData(gd_systemPathText);
+
+// selectSystemPathButton = new Button(composite, SWT.NONE);
+// selectSystemPathButton.setText("Select...");
+
+ new Label(composite, SWT.NONE);
+
+ optionalButton = new Button(composite, SWT.CHECK);
+ optionalButton.setText(Messages.EditDependencyDialog_optional_checkbox);
+ GridData gd_optionalButton = new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1);
+ gd_optionalButton.horizontalIndent = 4;
+ optionalButton.setLayoutData(gd_optionalButton);
+
+ composite.setTabList(new Control[] {groupIdText, artifactIdText, versionText, classifierText, typeCombo,
+ scopeCombo, systemPathText, /*selectSystemPathButton,*/optionalButton});
+
+ setDependency(dependency);
+
+ return superComposite;
+ }
+
+ @Override
+ protected void computeResult() {
+ if (dependency == null) {
+ dependency = new Dependency();
+ }
+ final String groupId = valueOrNull(groupIdText.getText());
+ final String artifactId = valueOrNull(artifactIdText.getText());
+ final String version = valueOrNull(versionText.getText());
+ final String type = valueOrNull(typeCombo.getText());
+ final String scope = valueOrNull(scopeCombo.getText());
+ final String classifier = valueOrNull(classifierText.getText());
+ final String system = valueOrNull(systemPathText.getText());
+
+ dependency.setArtifactId(artifactId);
+ dependency.setGroupId(groupId);
+ dependency.setType(type);
+ dependency.setVersion(version);
+ dependency.setScope(scope);
+ dependency.setClassifier(classifier);
+ dependency.setSystemPath(system);
+ boolean optional = optionalButton.getSelection();
+ if (optional != dependency.isOptional()) {
+ dependency.setOptional(optional);
+ }
+ }
+
+ private String valueOrNull(String value) {
+ if (value != null) {
+ value = value.trim();
+ if (value.length() == 0) {
+ value = null;
+ }
+ }
+ return value;
+ }
+
+
+ public void setDependency(Dependency dependency) {
+ this.dependency = dependency;
+
+ if(dependency != null
+ && groupIdText != null
+ && !groupIdText.isDisposed()) {
+ groupIdText.setText(nvl(dependency.getGroupId()));
+ artifactIdText.setText(nvl(dependency.getArtifactId()));
+ versionText.setText(nvl(dependency.getVersion()));
+ classifierText.setText(nvl(dependency.getClassifier()));
+ typeCombo.setText("".equals(nvl(dependency.getType())) ? "jar" : dependency.getType()); //$NON-NLS-1$ //$NON-NLS-2$
+ scopeCombo.setText("".equals(nvl(dependency.getScope())) ? "compile" : dependency.getScope()); //$NON-NLS-1$ //$NON-NLS-2$
+ systemPathText.setText(nvl(dependency.getSystemPath()));
+
+ boolean optional = Boolean.parseBoolean(dependency.getOptional());
+ if(optionalButton.getSelection() != optional) {
+ optionalButton.setSelection(optional);
+ }
+ }
+ }
+
+ /**
+ * @return the dependency
+ */
+ public Dependency getDependency() {
+ return dependency;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,500 @@
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.conversion.ui.dialog;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.model.Dependency;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.DialogCellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.jboss.tools.maven.conversion.ui.handlers.IdentifyJarJob;
+import org.jboss.tools.maven.conversion.ui.internal.MavenDependencyConversionActivator;
+import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
+import org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil;
+import org.jboss.tools.maven.sourcelookup.internal.identification.FileIdentificationManager;
+
+public class IdentifyMavenDependencyPage extends WizardPage {
+
+ private static final String SOURCE_PROPERTY = "SOURCE_PROPERTY";
+
+ private static final String DEPENDENCY_PROPERTY = "DEPENDENCY_PROPERTY";
+
+ private static final int DEPENDENCY_COLUMN = 2;
+
+ private Map<IClasspathEntry, Dependency> dependencyMap;
+
+ private Map<IClasspathEntry, IdentifyJarJob> identificationJobs;
+
+ private Set<IClasspathEntry> initialEntries;
+
+ private IProject project;
+
+ private Image jarImage;
+ private Image projectImage;
+ private Image okImage;
+ private Image failedImage;
+ private Image loadingImage;
+
+ private CheckboxTableViewer dependenciesViewer;
+
+ public IdentifyMavenDependencyPage(IProject project, Set<IClasspathEntry> entries) {
+ super("");
+ this.project = project;
+ initialEntries = Collections.unmodifiableSet(entries);
+ initDependencyMap();
+ }
+
+ private void initDependencyMap() {
+ dependencyMap = new LinkedHashMap<IClasspathEntry, Dependency>(initialEntries.size());
+ IJavaProject javaProject = JavaCore.create(project);
+ try {
+
+ for (IClasspathEntry entry : initialEntries) {
+ if ((entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath() != null)
+ || (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT)) {
+ dependencyMap.put(entry, null);
+ } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
+ IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject );
+ if (container != null) {
+ for (IClasspathEntry cpe: container.getClasspathEntries()) {
+ dependencyMap.put(cpe, null);
+ }
+ }
+ }
+ }
+
+ } catch(Exception e) {
+ setMessage(e.getLocalizedMessage());
+ }
+ }
+
+ private void initImages() {
+ jarImage = MavenDependencyConversionActivator.getJarIcon();
+ projectImage = MavenDependencyConversionActivator.getProjectIcon();
+ okImage = MavenDependencyConversionActivator.getOkIcon();
+ failedImage = MavenDependencyConversionActivator.getFailedIcon();
+ loadingImage = MavenDependencyConversionActivator.getLoadingIcon();
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+
+ setTitle("Identify Maven dependencies");
+
+ initImages();
+
+ Composite container = new Composite(parent, SWT.NONE);
+ container.setEnabled(true);
+ setControl(container);
+
+ GridLayout layout = new GridLayout(3, false);
+ layout.marginLeft = 12;
+ container.setLayout(layout);
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ String message = "Identify existing classpath entries as Maven dependencies";
+ setMessage(message);
+
+ displayDependenciesTable(container);
+
+ runIdentificationJobs();
+ }
+
+
+ private void displayDependenciesTable(Composite container) {
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 4);
+ gd.heightHint = 500;
+ gd.widthHint = 545;
+
+ dependenciesViewer = CheckboxTableViewer.newCheckList(container,
+ SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION );
+ Table table = dependenciesViewer.getTable();
+ table.setFocus();
+ table.setLayoutData(gd);
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+
+ TableColumn emptyColumn = new TableColumn(table, SWT.NONE);
+ emptyColumn.setWidth(20);
+
+ TableViewerColumn sourceColumn = new TableViewerColumn(dependenciesViewer, SWT.NONE);
+ sourceColumn.getColumn().setText("Classpath Entry ");
+ sourceColumn.getColumn().setWidth(270);
+ sourceColumn.setLabelProvider(new ColumnLabelProvider(){
+ @Override
+ @SuppressWarnings("unchecked")
+ public String getText(Object element) {
+ Map.Entry<IClasspathEntry, Dependency> entry = (Map.Entry<IClasspathEntry, Dependency>) element;
+ return entry.getKey().getPath().lastSegment();
+ }
+
+ @Override
+ public String getToolTipText(Object element) {
+ try {
+ return "SHA1 Checksum : "+IdentificationUtil.getSHA1(ConversionUtils.getFile(((Map.Entry<IClasspathEntry, Dependency>) element).getKey()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return "Unable to compute SHA1 Checksum";
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Image getImage(Object element) {
+ Map.Entry<IClasspathEntry, String> entry = (Map.Entry<IClasspathEntry, String>) element;
+ Image img;
+ if (entry.getKey().getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+ img = jarImage;
+ } else {
+ img = projectImage;
+ }
+ return img;
+ }
+ });
+
+ TableViewerColumn dependencyColumn = new TableViewerColumn(dependenciesViewer, SWT.NONE);
+ dependencyColumn.getColumn().setText("Maven Dependency");
+ dependencyColumn.getColumn().setWidth(270);
+ dependencyColumn.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ @SuppressWarnings("unchecked")
+ public String getText(Object element) {
+ Map.Entry<IClasspathEntry, Dependency> entry = (Map.Entry<IClasspathEntry, Dependency>) element;
+ IdentifyJarJob job = identificationJobs ==null? null:identificationJobs.get(entry.getKey());
+ if (job != null) {
+ int jobState = job.getState();
+ if (jobState == Job.RUNNING || jobState == Job.WAITING) {
+ return "Identification in progress...";
+ }
+ }
+ return IdentifyMavenDependencyPage.toString(entry.getValue());
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Image getImage(Object element) {
+ Map.Entry<IClasspathEntry, String> entry = (Map.Entry<IClasspathEntry, String>) element;
+ IdentifyJarJob job = identificationJobs ==null? null:identificationJobs.get(entry.getKey());
+ if (job != null) {
+ int jobState = job.getState();
+ if (jobState == Job.RUNNING || jobState == Job.WAITING) {
+ return loadingImage;
+ }
+ }
+ if (entry.getValue() == null) {
+ return failedImage;
+ } else {
+ return okImage;
+ }
+ }
+ });
+
+ dependenciesViewer.setContentProvider(ArrayContentProvider.getInstance());
+ dependenciesViewer.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ refresh();
+ }
+ });
+ dependenciesViewer.setInput(dependencyMap.entrySet());
+ dependenciesViewer.setAllChecked(true);
+
+ addSelectionButton(container, "Select All", true);
+ addSelectionButton(container, "Deselect All", false);
+ addIdentifyButton(container, "Identify dependencies");
+ //addResetButton(container, "Reset");
+
+ addCellEditors();
+ }
+
+
+ @Override
+ public boolean isPageComplete() {
+ return true;
+ }
+
+ protected void addCellEditors() {
+ dependenciesViewer.setColumnProperties(
+ new String[] { "EMPTY", SOURCE_PROPERTY, DEPENDENCY_PROPERTY });
+
+ DependencyCellEditor dce = new DependencyCellEditor(dependenciesViewer.getTable());
+ CellEditor[] editors = new CellEditor[] { null, null, dce};
+ dependenciesViewer.setCellEditors(editors);
+ dependenciesViewer.setCellModifier(new DependencyCellModifier());
+ }
+
+ private class DependencyCellModifier implements ICellModifier {
+
+ public boolean canModify(Object element, String property) {
+ return DEPENDENCY_PROPERTY.equals(property);
+ }
+
+ public Object getValue(Object element, String property) {
+ Map.Entry<IClasspathEntry, Dependency> entry = (Map.Entry<IClasspathEntry, Dependency>) element;
+ if (property.equals(SOURCE_PROPERTY)) {
+ return entry.getKey().getPath().toOSString();
+ } else if (property.equals(DEPENDENCY_PROPERTY)) {
+ return IdentifyMavenDependencyPage.toString(entry.getValue());
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public void modify(Object element, String property, Object value) {
+ if (property.equals(DEPENDENCY_PROPERTY)) {
+ TableItem item = (TableItem) element;
+ Map.Entry<IClasspathEntry, Dependency> entry = (Map.Entry<IClasspathEntry, Dependency>) item.getData();
+ if (value instanceof Dependency) {
+ entry.setValue((Dependency)value);
+ refresh();
+ }
+ }
+ }
+ }
+
+ private class DependencyCellEditor extends DialogCellEditor {
+
+ DependencyCellEditor (Composite parent) {
+ super(parent);
+ }
+
+ protected Button createButton(Composite parent) {
+ Button result = new Button(parent, SWT.DOWN);
+ result.setText("Edit..."); //$NON-NLS-1$
+ return result;
+ }
+
+ @Override
+ protected Object openDialogBox(Control cellEditorWindow) {
+ Table table = (Table)cellEditorWindow.getParent();
+ int idx = table.getSelectionIndex();
+ Dependency d= ((Map.Entry<IClasspathEntry, Dependency>) table.getItem(idx).getData()).getValue();
+ EditDependencyDialog editDependencyDialog = new EditDependencyDialog(cellEditorWindow.getShell());
+ editDependencyDialog.setDependency(d);
+ if(editDependencyDialog.open() == Window.OK) {
+ return editDependencyDialog.getDependency();
+ }
+ return d;
+ }
+
+ }
+
+
+ private Button addSelectionButton(Composite container, String label,
+ final boolean ischecked) {
+ Button button = new Button(container, SWT.NONE);
+ button.setLayoutData(new GridData(SWT.FILL, SWT.UP, false, false, 1, 1));
+ button.setText(label);
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ dependenciesViewer.setAllChecked(ischecked);
+ refresh();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return button;
+ }
+
+ private Button addResetButton(Composite container, String label) {
+ Button button = new Button(container, SWT.NONE);
+ button.setLayoutData(new GridData(SWT.FILL, SWT.UP, false, false, 1, 1));
+ button.setText(label);
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ initDependencyMap( );
+ dependenciesViewer.setInput(dependencyMap.entrySet());
+ dependenciesViewer.setAllChecked(true);
+ refresh();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return button;
+ }
+
+
+ private Button addIdentifyButton(Composite container, String label) {
+ Button button = new Button(container, SWT.NONE);
+ button.setLayoutData(new GridData(SWT.FILL, SWT.UP, false, false, 1, 1));
+ button.setText(label);
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ runIdentificationJobs();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return button;
+ }
+
+ protected void runIdentificationJobs() {
+
+ initJobs();
+ for (Map.Entry<IClasspathEntry, Dependency> entry : dependencyMap.entrySet()) {
+ if (entry.getValue() != null) {
+ //don't need to run identification
+ continue;
+ }
+ IdentifyJarJob job = identificationJobs.get(entry.getKey());
+ if (job != null) {
+ int jobState = job.getState();
+ if (jobState == Job.NONE) {
+ job.schedule();
+ }
+ }
+ }
+
+ }
+
+ protected void refresh() {
+ if (dependenciesViewer != null && !dependenciesViewer.getTable().isDisposed()) {
+ dependenciesViewer.refresh();
+ }
+ }
+
+
+ static String toString(Dependency d) {
+ if (d == null) {
+ return " Unidentified dependency";
+ }
+ StringBuilder text = new StringBuilder(" ");
+ text.append(d.getGroupId())
+ .append(":")
+ .append(d.getArtifactId())
+ .append(":")
+ .append(d.getVersion());
+ return text.toString();
+ }
+
+ void initJobs() {
+ if (identificationJobs == null) {
+ identificationJobs = new HashMap<IClasspathEntry, IdentifyJarJob>(dependencyMap.size());
+
+ Table t = dependenciesViewer.getTable();
+ IFileIdentificationManager fileIdentificationManager = new FileIdentificationManager();
+
+ for (final TableItem item : t.getItems()) {
+ final Map.Entry<IClasspathEntry, Dependency> entry = (Map.Entry<IClasspathEntry, Dependency>)item.getData();
+ if (entry.getValue() != null) {
+ //already identified
+ continue;
+ }
+ File jar;
+ try {
+ jar = ConversionUtils.getFile(entry.getKey());
+
+ final IdentifyJarJob job = new IdentifyJarJob("Search the Maven coordinates for "+jar.getAbsolutePath(), fileIdentificationManager, jar);
+ job.addJobChangeListener(new IJobChangeListener() {
+
+ @Override
+ public void sleeping(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void scheduled(IJobChangeEvent event) {
+ item.setImage(DEPENDENCY_COLUMN, loadingImage);
+ item.setText(DEPENDENCY_COLUMN, "Identification in progress...");
+ }
+
+ @Override
+ public void running(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ Dependency d = job.getDependency();
+ dependencyMap.put(entry.getKey(), d);
+ refresh();
+ }
+ });
+ }
+
+ @Override
+ public void awake(IJobChangeEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void aboutToRun(IJobChangeEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+ identificationJobs.put(entry.getKey(), job);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ public List<Dependency> getDependencies() {
+
+ Object[] selection = dependenciesViewer.getCheckedElements();
+ List<Dependency> dependencies = new ArrayList<Dependency>(selection.length);
+ for (Object o : selection) {
+ Map.Entry<IClasspathEntry, Dependency> entry = (Map.Entry<IClasspathEntry, Dependency>) o;
+ dependencies.add(entry.getValue());
+ }
+ return dependencies;
+ }
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,127 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.conversion.ui.handlers;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.maven.conversion.ui.dialog.ConvertToMavenDependencyWizard;
+
+/**
+ * Materialize Library Handler.
+ *
+ * @author Fred Bricon
+ */
+
+@SuppressWarnings("restriction")
+public class ConvertToMavenDependencyHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+
+ final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+ Set<IClasspathEntry> entries = getSelectedClasspathEntries(selection);
+
+ //System.err.println(entries);
+
+ if (entries == null || entries.isEmpty()) {
+ MessageDialogWithToggle.openInformation(window.getShell(), "Convert to Maven Dependency", "Nothing to convert");
+ return null;
+ }
+
+ /*
+ IPath path = libraryFromUI.getClasspathEntry().getPath();
+
+ IJavaProject javaProject = libraryFromUI.getJavaProject();
+
+ final String libName = libraryFromUI.getLabel();
+ */
+ /*
+ IClasspathContainer containerToMaterialize = JavaCore.getClasspathContainer(path, javaProject);
+
+ IProject project = javaProject.getProject();
+
+ */
+ ConvertToMavenDependencyWizard wizard = new ConvertToMavenDependencyWizard(
+ null, //project,
+ entries
+ );
+
+ WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
+ dialog.open();
+ return null;
+ }
+
+
+ private Set<IClasspathEntry> getSelectedClasspathEntries(ISelection selection) {
+ Set<IClasspathEntry> files = null;
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ files = new LinkedHashSet<IClasspathEntry>(structuredSelection.size());
+ Iterator<?> ite = structuredSelection.iterator();
+ while(ite.hasNext()) {
+ Object o = ite.next();
+ if (o instanceof IPackageFragmentRoot) {
+ ((IPackageFragmentRoot) o).getPath();
+ addClasspathEntry((IPackageFragmentRoot)o, files);
+ }
+ else if (o instanceof ClassPathContainer) {
+ ClassPathContainer container = (ClassPathContainer) o;
+ if (isValid(container)) {
+ for (IPackageFragmentRoot pfr : container.getPackageFragmentRoots()) {
+ addClasspathEntry(pfr, files);
+ }
+ }
+ }
+ }
+ }
+ return files;
+ }
+
+
+ private boolean isValid(ClassPathContainer container) {
+ return !MavenClasspathHelpers.isMaven2ClasspathContainer(container.getClasspathEntry().getPath());
+ }
+
+ private void addClasspathEntry(IPackageFragmentRoot pfr, Collection<IClasspathEntry> entries) {
+ if (pfr.isArchive()) {
+ pfr.getResource();
+ try {
+ IClasspathEntry cpe = pfr.getResolvedClasspathEntry();
+ if (cpe != null && cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+ entries.add(cpe);
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
\ No newline at end of file
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,52 @@
+package org.jboss.tools.maven.conversion.ui.handlers;
+
+import java.io.File;
+
+import org.apache.maven.model.Dependency;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.jboss.tools.maven.conversion.ui.internal.MavenDependencyConversionActivator;
+import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
+
+public class IdentifyJarJob extends Job {
+
+ private File file;
+
+ private IFileIdentificationManager fileIdentificationManager;
+
+ private Dependency dependency;
+
+ public IdentifyJarJob(String name, IFileIdentificationManager fileIdentificationManager, File file) {
+ super(name);
+ this.fileIdentificationManager = fileIdentificationManager;
+ this.file = file;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ ArtifactKey artifactKey;
+ try {
+ artifactKey = fileIdentificationManager.identify(file, monitor);
+ } catch (CoreException e) {
+ return new Status(IStatus.ERROR, MavenDependencyConversionActivator.PLUGIN_ID, e.getMessage(), e);
+ }
+ if (artifactKey != null) {
+ dependency = new Dependency();
+ dependency.setArtifactId(artifactKey.getArtifactId());
+ dependency.setGroupId(artifactKey.getGroupId());
+ dependency.setVersion(artifactKey.getVersion());
+ dependency.setClassifier(artifactKey.getClassifier());
+ }
+ return Status.OK_STATUS;
+ }
+
+ public Dependency getDependency() {
+ return dependency;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,82 @@
+package org.jboss.tools.maven.conversion.ui.internal;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.m2e.core.project.conversion.AbstractProjectConversionParticipant;
+import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.maven.conversion.ui.dialog.ConvertToMavenDependencyWizard;
+
+public class ClasspathConversionParticipant extends
+ AbstractProjectConversionParticipant {
+
+ @Override
+ public boolean accept(IProject project) throws CoreException {
+ return project.hasNature(JavaCore.NATURE_ID);
+ }
+
+ @Override
+ public void convert(final IProject project, final Model model, final IProgressMonitor monitor)
+ throws CoreException {
+
+ if (accept(project)) {
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] classpath = javaProject.getRawClasspath();
+ Set<IClasspathEntry> entries = new LinkedHashSet<IClasspathEntry>(classpath.length);
+ for (IClasspathEntry cpe : classpath) {
+ if (isValid(cpe)) {
+ entries.add(cpe);
+ }
+ }
+
+ if (entries.isEmpty()) {
+ return;
+ }
+
+ final ConvertToMavenDependencyWizard conversionWizard = new ConvertToMavenDependencyWizard(project, entries);
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ WizardDialog dialog = new WizardDialog(shell, conversionWizard);
+ if (dialog.open() == Window.OK) {
+ List<Dependency> dependencies = conversionWizard.getDependencies();
+ if (dependencies != null && !dependencies.isEmpty()) {
+ model.setDependencies(dependencies);
+ }
+ }
+ }
+ });
+ }
+ }
+
+ private boolean isValid(IClasspathEntry cpe) {
+
+ if(IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind()
+ && ("org.eclipse.jdt.launching.JRE_CONTAINER".equals(cpe.getPath().segment(0))
+ || MavenClasspathHelpers.isMaven2ClasspathContainer(cpe.getPath()))) {
+ return false;
+ }
+ if (IClasspathEntry.CPE_SOURCE == cpe.getEntryKind()) {
+ return false;
+ }
+ return true;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/GenericCommandActionDelegate.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/GenericCommandActionDelegate.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/GenericCommandActionDelegate.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Red Hat - minor refactoring
+ *
+ * Original code taken from <a href="http://wiki.eclipse.org/Platform_Command_Framework#Using_an_IActionDelega...">
+ * http://wiki.eclipse.org/Platform_Command_Framework#Using_an_IActionDelega...</a>
+ ******************************************************************************/
+package org.jboss.tools.maven.conversion.ui.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
+
+/**
+ * This action delegate can be used to specify a command with or without
+ * parameters be called from an <action/> specified in actionSets,
+ * editorActions, viewActions, or popupMenus.
+ */
+public class GenericCommandActionDelegate implements
+ IWorkbenchWindowActionDelegate, IViewActionDelegate,
+ IEditorActionDelegate, IObjectActionDelegate, IExecutableExtension {
+
+ /**
+ * The commandId parameter needed when using the <class/> form for
+ * this IActionDelegate. Value is "commandId".
+ */
+ public static final String PARM_COMMAND_ID = "commandId"; //$NON-NLS-1$
+
+ private String commandId = null;
+
+ private Map<?, ?> parameterMap = null;
+
+ private ParameterizedCommand parameterizedCommand = null;
+
+ private IHandlerService handlerService = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+ */
+ public void dispose() {
+ handlerService = null;
+ parameterizedCommand = null;
+ parameterMap = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ if (handlerService == null) {
+ // what, no handler service ... no problem
+ return;
+ }
+ try {
+ if (commandId != null) {
+ handlerService.executeCommand(commandId, null);
+ } else if (parameterizedCommand != null) {
+ handlerService.executeCommand(parameterizedCommand, null);
+ }
+ // else there is no command for this delegate
+ } catch (Exception e) {
+ // exceptions reduced for brevity
+ // and we won't just do a print out :-)
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
+ * org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ // we don't care, handlers get their selection from the
+ // ExecutionEvent application context
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
+ * java.lang.String, java.lang.Object)
+ */
+ public void setInitializationData(IConfigurationElement config,
+ String propertyName, Object data) throws CoreException {
+ String id = config.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
+ // save the data until our init(*) call, where we can get
+ // the services.
+ if (data instanceof String) {
+ commandId = (String) data;
+ } else if (data instanceof Map) {
+ parameterMap = (Map<?, ?>) data;
+ if (parameterMap.get(PARM_COMMAND_ID) == null) {
+ Status status = new Status(IStatus.ERROR,
+ "org.jboss.tools.maven.ui.generic", "The '" + id
+ + "' action won't work without a commandId");
+ throw new CoreException(status);
+ }
+ } else {
+ Status status = new Status(
+ IStatus.ERROR,
+ "org.jboss.tools.maven.ui.generic",
+ "The '"
+ + id
+ + "' action won't work without some initialization parameters");
+ throw new CoreException(status);
+ }
+ }
+
+ /**
+ * Build a command from the executable extension information.
+ *
+ * @param commandService
+ * to get the Command object
+ */
+ private void createCommand(ICommandService commandService) {
+ String id = (String) parameterMap.get(PARM_COMMAND_ID);
+ if (id == null) {
+ return;
+ }
+ if (parameterMap.size() == 1) {
+ commandId = id;
+ return;
+ }
+ try {
+ Command cmd = commandService.getCommand(id);
+ if (!cmd.isDefined()) {
+ // command not defined? no problem ...
+ return;
+ }
+ ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
+ Iterator<?> i = parameterMap.keySet().iterator();
+ while (i.hasNext()) {
+ String parmName = (String) i.next();
+ if (PARM_COMMAND_ID.equals(parmName)) {
+ continue;
+ }
+ IParameter parm = cmd.getParameter(parmName);
+ if (parm == null) {
+ // asking for a bogus parameter? No problem
+ return;
+ }
+ parameters.add(new Parameterization(parm, (String) parameterMap
+ .get(parmName)));
+ }
+ parameterizedCommand = new ParameterizedCommand(cmd,
+ (Parameterization[]) parameters
+ .toArray(new Parameterization[parameters.size()]));
+ } catch (NotDefinedException e) {
+ // command is bogus? No problem, we'll do nothing.
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+ */
+ public void init(IWorkbenchWindow window) {
+ if (handlerService != null) {
+ // already initialized
+ return;
+ }
+
+ handlerService = (IHandlerService) window
+ .getService(IHandlerService.class);
+ if (parameterMap != null) {
+ ICommandService commandService = (ICommandService) window
+ .getService(ICommandService.class);
+ createCommand(commandService);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
+ */
+ public void init(IViewPart view) {
+ init(view.getSite().getWorkbenchWindow());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IEditorPart)
+ */
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ // we don't actually care about the active editor, since that
+ // information is in the ExecutionEvent application context
+ // but we need to make sure we're initialized.
+ if (targetEditor != null) {
+ init(targetEditor.getSite().getWorkbenchWindow());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // we don't actually care about the active part, since that
+ // information is in the ExecutionEvent application context
+ // but we need to make sure we're initialized.
+ if (targetPart != null) {
+ init(targetPart.getSite().getWorkbenchWindow());
+ }
+ }
+}
+
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/MavenDependencyConversionActivator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/MavenDependencyConversionActivator.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/MavenDependencyConversionActivator.java 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,106 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.conversion.ui.internal;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class MavenDependencyConversionActivator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.maven.conversion.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static MavenDependencyConversionActivator plugin;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static MavenDependencyConversionActivator getDefault() {
+ return plugin;
+ }
+
+ public static void log(Exception e, String message) {
+ IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e);
+ plugin.getLog().log(status);
+ }
+
+ public static void logWarning(String message) {
+ IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message);
+ plugin.getLog().log(status);
+ }
+
+ public static void log(Throwable e) {
+ IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e
+ .getLocalizedMessage(), e);
+ plugin.getLog().log(status);
+ }
+
+ public static Image getJarIcon() {
+ return getIcon("icons/jar_obj.gif");
+ }
+
+ public static Image getProjectIcon() {
+ return getIcon("icons/projects.gif");
+ }
+
+ public static Image getOkIcon() {
+ return getIcon("icons/passed.png");
+ }
+
+ public static Image getFailedIcon() {
+ return getIcon("icons/error_st_obj.gif");
+ }
+
+
+ public static Image getLoadingIcon() {
+ //animated gifs (loader.gif) )are not animated when used inside cells of tableviewer
+ //using an alternate icon to represent search
+ return getIcon("icons/find_obj.gif");
+ }
+
+ public static Image getIcon(String pathToIcon) {
+ Image img = null;
+ ImageDescriptor descriptor = imageDescriptorFromPlugin(PLUGIN_ID, pathToIcon);
+ if(descriptor != null) {
+ img = descriptor.createImage();
+ }
+ return img;
+ }
+
+}
\ No newline at end of file
Added: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/messages.properties
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/messages.properties (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/messages.properties 2012-07-24 16:47:41 UTC (rev 42694)
@@ -0,0 +1,9 @@
+Convert_Maven_Dependency=Convert to Maven Dependencies
+
+Maven_Configuration_Warning =This will also remove the Maven configuration from this project.
+Maven_Configuration_Dialog_Warning = This will also remove the Maven configuration from this project.\nThis operation cannot be undone, are you sure ?
+Gradle_Configuration_Warning =This will also remove the Gradle configuration from this project.
+Gradle_Configuration_Dialog_Warning = This will also remove the Gradle configuration from this project.\nThis operation cannot be undone, are you sure ?
+Jre_Warning = Materializing {0} might have unexpected consequences and is not recommended.
+Jre_Dialog_Warning = Materializing {0} might have unexpected consequences and is not recommended. Are you sure?
+
Modified: trunk/maven/plugins/pom.xml
===================================================================
--- trunk/maven/plugins/pom.xml 2012-07-24 16:31:18 UTC (rev 42693)
+++ trunk/maven/plugins/pom.xml 2012-07-24 16:47:41 UTC (rev 42694)
@@ -30,6 +30,7 @@
<module>org.jboss.tools.maven.gwt</module>
<module>org.jboss.tools.maven.sourcelookup.core</module>
<module>org.jboss.tools.maven.sourcelookup.ui</module>
+ <module>org.jboss.tools.maven.conversion.ui</module>
<module>org.jboss.tools.maven.jdt</module>
</modules>
</project>
13 years, 5 months
JBoss Tools SVN: r42693 - in trunk/maven/plugins: org.jboss.tools.maven.sourcelookup.core/META-INF and 7 other directories.
by jbosstools-commits@lists.jboss.org
Author: fbricon
Date: 2012-07-24 12:31:18 -0400 (Tue, 24 Jul 2012)
New Revision: 42693
Added:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.settings/org.eclipse.m2e.core.prefs
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/ArtifactIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IFileIdentificationManager.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IdentificationUtil.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/FileIdentificationManager.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/MavenPropertiesIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusIndexIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusRepositoryIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/.settings/org.eclipse.m2e.core.prefs
Modified:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java
Log:
JBIDE-12314 : Extract file identification API for the Maven Source Lookup Plugin - part 1
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.settings/org.eclipse.m2e.core.prefs
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.settings/org.eclipse.m2e.core.prefs (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.settings/org.eclipse.m2e.core.prefs 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Modified: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF 2012-07-24 16:02:08 UTC (rev 42692)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF 2012-07-24 16:31:18 UTC (rev 42693)
@@ -20,6 +20,8 @@
Bundle-Vendor: %BundleVendor
Bundle-Localization: plugin
Export-Package: org.jboss.tools.maven.sourcelookup,
- org.jboss.tools.maven.sourcelookup.containers
+ org.jboss.tools.maven.sourcelookup.containers,
+ org.jboss.tools.maven.sourcelookup.identification,
+ org.jboss.tools.maven.sourcelookup.internal.identification
Bundle-ClassPath: .,
lib/nexus-indexer-lucene-rest-api-client.jar
Modified: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java 2012-07-24 16:02:08 UTC (rev 42692)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -10,34 +10,24 @@
************************************************************************************/
package org.jboss.tools.maven.sourcelookup.containers;
+import static org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil.getSourcesClassifier;
+
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
-import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Unmarshaller;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
@@ -49,13 +39,6 @@
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.IMaven;
-import org.eclipse.m2e.core.internal.index.IIndex;
-import org.eclipse.m2e.core.internal.index.IndexManager;
-import org.eclipse.m2e.core.internal.index.IndexedArtifactFile;
-import org.eclipse.m2e.core.internal.index.nexus.NexusIndex;
-import org.eclipse.m2e.core.internal.index.nexus.NexusIndexManager;
-import org.eclipse.m2e.core.repository.IRepository;
-import org.eclipse.m2e.core.repository.IRepositoryRegistry;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerUtil;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
@@ -66,10 +49,9 @@
import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.tools.maven.sourcelookup.NexusRepository;
import org.jboss.tools.maven.sourcelookup.SourceLookupActivator;
-import org.sonatype.nexus.rest.model.NexusArtifact;
-import org.sonatype.nexus.rest.model.SearchResponse;
+import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
+import org.jboss.tools.maven.sourcelookup.internal.identification.FileIdentificationManager;
/**
*
@@ -79,9 +61,6 @@
public class JBossSourceContainer extends AbstractSourceContainer {
private static final String PATH_SEPARATOR = "/";
- private static final String CLASSIFIER_SOURCES = "sources"; //$NON-NLS-1$
- private static final String CLASSIFIER_TESTS = "tests"; //$NON-NLS-1$
- private static final String CLASSIFIER_TESTSOURCES = "test-sources"; //$NON-NLS-1$
public static final String TYPE_ID = "org.jboss.tools.maven.sourcelookup.containerType"; //$NON-NLS-1$
public static final String EAP = "EAP"; //$NON-NLS-1$
@@ -95,8 +74,9 @@
private List<ISourceContainer> sourceContainers = new ArrayList<ISourceContainer>();
protected static File resolvedFile;
private String homePath;
- private static List<IRepository> globalRepositories;
+ private IFileIdentificationManager fileIdentificationManager;
+
public JBossSourceContainer(ILaunchConfiguration configuration)
throws CoreException {
IServer server = ServerUtil.getServer(configuration);
@@ -116,24 +96,12 @@
SourceLookupActivator.PLUGIN_ID, "Invalid configuration");
throw new CoreException(status);
}
- initialize();
+ fileIdentificationManager = new FileIdentificationManager();
}
- private static void initialize() throws CoreException {
- IRepositoryRegistry repositoryRegistry = MavenPlugin
- .getRepositoryRegistry();
- globalRepositories = repositoryRegistry
- .getRepositories(IRepositoryRegistry.SCOPE_SETTINGS);
- MavenPlugin.getMaven().reloadSettings();
- }
-
public JBossSourceContainer(String homePath) {
this.homePath = homePath;
- try {
- initialize();
- } catch (CoreException e) {
- SourceLookupActivator.log(e);
- }
+ fileIdentificationManager = new FileIdentificationManager();
}
private List<File> getJars() throws CoreException {
@@ -152,20 +120,20 @@
if (JBossServerType.AS7.equals(type)) {
getAS7xJars();
}
- if (JBossServerType.AS.equals(type)) {
+ else if (JBossServerType.AS.equals(type)) {
if (IJBossToolingConstants.V6_0.equals(version)
|| IJBossToolingConstants.V6_1.equals(version)) {
getAS6xJars();
}
- if (IJBossToolingConstants.V5_0.equals(version)
+ else if (IJBossToolingConstants.V5_0.equals(version)
|| IJBossToolingConstants.V5_1.equals(version)) {
getAS5xJars();
}
}
- if (JBossServerType.EAP6.equals(type)) {
+ else if (JBossServerType.EAP6.equals(type)) {
getAS7xJars();
}
- if (JBossServerType.SOAP.equals(type) || JBossServerType.EAP.equals(type) || EPP.equals(type)
+ else if (JBossServerType.SOAP.equals(type) || JBossServerType.EAP.equals(type) || EPP.equals(type)
|| JBossServerType.SOAP_STD.equals(type) || JBossServerType.EWP.equals(type)
|| JBossServerType.EAP_STD.equals(type)) {
@@ -272,7 +240,7 @@
className = className.replace("\\", PATH_SEPARATOR);
ZipEntry entry = jar.getEntry(className);//$NON-NLS-1$
if (entry != null) {
- ArtifactKey artifact = getArtifact(file, jar);
+ ArtifactKey artifact = getArtifact(file);
if (artifact != null) {
IPath sourcePath = getSourcePath(artifact);
if (sourcePath == null) {
@@ -326,224 +294,10 @@
return objects;
}
- public static ArtifactKey getArtifact(File file, ZipFile jar)
- throws CoreException, IOException {
- ArtifactKey artifact = getArtifactFromM2eIndex(file);
- if (artifact == null) {
- artifact = getArtifactFromMetaInf(jar);
- }
- if (artifact == null) {
- artifact = getArtifactFromJBossNexusRepository(file);
- }
- return artifact;
+ public ArtifactKey getArtifact(File file) throws CoreException {
+ return fileIdentificationManager.identify(file, new NullProgressMonitor());
}
- private static ArtifactKey getArtifactFromJBossNexusRepository(String sha1,
- NexusRepository nexusRepository) {
- if (sha1 == null || nexusRepository == null
- || nexusRepository.getUrl() == null) {
- return null;
- }
- HttpURLConnection connection = null;
- try {
- String base = nexusRepository.getUrl();
- if (!base.endsWith(PATH_SEPARATOR)) {
- base = base + PATH_SEPARATOR;
- }
- // String url =
- // "https://repository.jboss.org/nexus/service/local/data_index?sha1=";
- String url = base + "service/local/data_index?sha1=";
- url = url + URLEncoder.encode(sha1, "UTF-8");
- JAXBContext context = JAXBContext.newInstance(SearchResponse.class);
- Unmarshaller unmarshaller = context.createUnmarshaller();
- connection = (HttpURLConnection) new URL(url).openConnection();
- connection.connect();
- Object object = unmarshaller.unmarshal(connection.getInputStream());
- if (object instanceof SearchResponse) {
- SearchResponse searchResponse = (SearchResponse) object;
- for (NexusArtifact nexusArtifact : searchResponse.getData()) {
- String groupId = nexusArtifact.getGroupId();
- String artifactId = nexusArtifact.getArtifactId();
- String version = nexusArtifact.getVersion();
- String classifier = nexusArtifact.getClassifier();
- ArtifactKey artifact = new ArtifactKey(groupId, artifactId,
- version, classifier);
- return artifact;
- }
- }
- } catch (Exception e) {
- return null;
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- return null;
- }
-
- private static ArtifactKey getArtifactFromJBossNexusRepository(File file) {
- String sha1;
- try {
- sha1 = getSHA1(file);
- } catch (Exception e) {
- return null;
- }
- Set<NexusRepository> nexusRepositories = SourceLookupActivator
- .getNexusRepositories();
- for (NexusRepository repository : nexusRepositories) {
- if (!repository.isEnabled()) {
- continue;
- }
- ArtifactKey key = getArtifactFromJBossNexusRepository(sha1,
- repository);
- if (key != null) {
- ArtifactKey sourcesArtifact = new ArtifactKey(
- key.getGroupId(), key.getArtifactId(),
- key.getVersion(),
- getSourcesClassifier(key.getClassifier()));
- ArtifactKey resolvedKey = getSourcesArtifactFromJBossNexusRepository(sourcesArtifact, repository);
- if (resolvedKey != null) {
- return key;
- }
- }
- }
- return null;
- }
-
- private static ArtifactKey getSourcesArtifactFromJBossNexusRepository(ArtifactKey key,
- NexusRepository nexusRepository) {
- if (key == null || nexusRepository == null
- || nexusRepository.getUrl() == null) {
- return null;
- }
- HttpURLConnection connection = null;
- try {
- String base = nexusRepository.getUrl();
- if (!base.endsWith(PATH_SEPARATOR)) {
- base = base + PATH_SEPARATOR;
- }
- // String url =
- // "https://repository.jboss.org/nexus/service/local/data_index?g=groupId&a=a...";
- String url = base + "service/local/data_index?";
- url= url + "g=" + URLEncoder.encode(key.getGroupId(), "UTF-8") + "&";
- url= url + "a=" + URLEncoder.encode(key.getArtifactId(), "UTF-8") + "&";
- url= url + "v=" + URLEncoder.encode(key.getVersion(), "UTF-8") + "&";
- url= url + "c=" + URLEncoder.encode(key.getClassifier(), "UTF-8");
- JAXBContext context = JAXBContext.newInstance(SearchResponse.class);
- Unmarshaller unmarshaller = context.createUnmarshaller();
- connection = (HttpURLConnection) new URL(url).openConnection();
- connection.connect();
- Object object = unmarshaller.unmarshal(connection.getInputStream());
- if (object instanceof SearchResponse) {
- SearchResponse searchResponse = (SearchResponse) object;
- for (NexusArtifact nexusArtifact : searchResponse.getData()) {
- String groupId = nexusArtifact.getGroupId();
- String artifactId = nexusArtifact.getArtifactId();
- String version = nexusArtifact.getVersion();
- String classifier = nexusArtifact.getClassifier();
- ArtifactKey artifact = new ArtifactKey(groupId, artifactId,
- version, classifier);
- return artifact;
- }
- }
- } catch (Exception e) {
- return null;
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- return null;
- }
- private static String getSHA1(File file) throws IOException,
- NoSuchAlgorithmException {
- MessageDigest md = MessageDigest.getInstance("SHA1");
- InputStream inputStream = new FileInputStream(file);
- byte[] bytes = new byte[16 * 1024];
- int count = 0;
- while ((count = inputStream.read(bytes)) != -1) {
- md.update(bytes, 0, count);
- }
- byte[] digestBytes = md.digest();
- StringBuffer sb = new StringBuffer("");
- for (int i = 0; i < digestBytes.length; i++) {
- sb.append(Integer.toString((digestBytes[i] & 0xff) + 0x100, 16)
- .substring(1));
- }
- return sb.toString();
- }
-
- protected static ArtifactKey getArtifactFromMetaInf(ZipFile jar)
- throws IOException {
- ZipEntry mavenEntry = jar.getEntry("META-INF/maven");//$NON-NLS-1$
- if (mavenEntry == null) {
- return null;
- }
- String entryName = mavenEntry.getName();
- Enumeration<? extends ZipEntry> zipEntries = jar.entries();
- ArtifactKey artifact = null;
- while (zipEntries.hasMoreElements()) {
- ZipEntry zipEntry = zipEntries.nextElement();
- if (zipEntry.getName().endsWith("pom.properties")
- && zipEntry.getName().startsWith(entryName)) {
- Properties props = new Properties();
- props.load(jar.getInputStream(zipEntry));
- String groupId = props.getProperty("groupId");
- String artifactId = props.getProperty("artifactId");
- String version = props.getProperty("version");
- String classifier = props.getProperty("classifier");
- if (groupId != null && artifactId != null && version != null) {
- artifact = new ArtifactKey(groupId, artifactId, version,
- classifier);
- return artifact;
- }
- }
- }
- return artifact;
- }
-
- protected static ArtifactKey getArtifactFromM2eIndex(File file)
- throws CoreException {
- IndexManager indexManager = MavenPlugin.getIndexManager();
- IIndex index = indexManager.getAllIndexes();
- IndexedArtifactFile info = null;
- try {
- info = index.identify(file);
- } catch (Throwable e) {
- // ignore
- }
- ArtifactKey artifact = null;
- if (info != null) {
- artifact = info.getArtifactKey();
- if (artifact != null) {
- return artifact;
- }
- }
- if (indexManager instanceof NexusIndexManager) {
- NexusIndexManager nexusIndexManager = (NexusIndexManager) indexManager;
- if (globalRepositories == null) {
- initialize();
- }
- for (IRepository repository : globalRepositories) {
- NexusIndex nexusIndex = nexusIndexManager.getIndex(repository);
- if (nexusIndex != null) {
- try {
- info = nexusIndex.identify(file);
- } catch (Throwable t) {
- // ignore
- }
- if (info != null) {
- artifact = info.getArtifactKey();
- if (artifact != null) {
- return artifact;
- }
- }
- }
- }
- }
- return artifact;
- }
-
public static Job downloadArtifact(File file, ArtifactKey artifact) {
final ArtifactKey sourcesArtifact = new ArtifactKey(
artifact.getGroupId(), artifact.getArtifactId(),
@@ -592,11 +346,6 @@
return resolved;
}
- static String getSourcesClassifier(String baseClassifier) {
- return CLASSIFIER_TESTS.equals(baseClassifier) ? CLASSIFIER_TESTSOURCES
- : CLASSIFIER_SOURCES;
- }
-
public static IPath getSourcePath(ArtifactKey a) {
File file = getAttachedArtifactFile(a,
getSourcesClassifier(a.getClassifier()));
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/ArtifactIdentifier.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/ArtifactIdentifier.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/ArtifactIdentifier.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,22 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.sourcelookup.identification;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+
+public interface ArtifactIdentifier {
+
+ ArtifactKey identify(File file) throws CoreException;
+
+}
\ No newline at end of file
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IFileIdentificationManager.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IFileIdentificationManager.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IFileIdentificationManager.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,29 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.sourcelookup.identification;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+
+/**
+ * Manager
+ *
+ * @author Fred Bricon
+ *
+ */
+public interface IFileIdentificationManager {
+
+ ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException;
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IdentificationUtil.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IdentificationUtil.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IdentificationUtil.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,62 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.sourcelookup.identification;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class IdentificationUtil {
+
+ private static final String CLASSIFIER_SOURCES = "sources"; //$NON-NLS-1$
+ private static final String CLASSIFIER_TESTS = "tests"; //$NON-NLS-1$
+ private static final String CLASSIFIER_TESTSOURCES = "test-sources"; //$NON-NLS-1$
+
+ private IdentificationUtil() {}
+
+ public static String getSHA1(File file) throws IOException,
+ NoSuchAlgorithmException {
+
+ InputStream inputStream = null;
+ StringBuilder sb = new StringBuilder();
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA1");
+ inputStream = new FileInputStream(file);
+ byte[] bytes = new byte[16 * 1024];
+ int count = 0;
+ while ((count = inputStream.read(bytes)) != -1) {
+ md.update(bytes, 0, count);
+ }
+ byte[] digestBytes = md.digest();
+ for (int i = 0; i < digestBytes.length; i++) {
+ sb.append(Integer.toString((digestBytes[i] & 0xff) + 0x100, 16)
+ .substring(1));
+ }
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (Exception e){
+ //ignore
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+ public static String getSourcesClassifier(String baseClassifier) {
+ return CLASSIFIER_TESTS.equals(baseClassifier) ? CLASSIFIER_TESTSOURCES
+ : CLASSIFIER_SOURCES;
+ }
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/FileIdentificationManager.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/FileIdentificationManager.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/FileIdentificationManager.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,62 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * 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
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.sourcelookup.internal.identification;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
+import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
+
+/**
+ *
+ * @author Fred Bricon
+ *
+ */
+public class FileIdentificationManager implements IFileIdentificationManager {
+
+ private List<ArtifactIdentifier> artifactIdentifiers;
+
+ public FileIdentificationManager() {
+ initArtifactIdentifiers();
+ }
+
+ private void initArtifactIdentifiers() {
+ //TODO read from extension points?
+ artifactIdentifiers = new ArrayList<ArtifactIdentifier>(3);
+ artifactIdentifiers.add(new MavenPropertiesIdentifier());
+ artifactIdentifiers.add(new NexusIndexIdentifier());
+ artifactIdentifiers.add(new NexusRepositoryIdentifier());
+ }
+
+ @Override
+ public ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException {
+ ArtifactKey artifactKey = null;
+ long start = System.currentTimeMillis();
+ for (ArtifactIdentifier identifier : artifactIdentifiers) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ artifactKey = identifier.identify(file);
+ if (artifactKey != null) {
+ long stop = System.currentTimeMillis();
+ System.err.println(file.getName() + " identified as " + artifactKey + " in " + (stop-start) + " ms");
+ break;
+ }
+ }
+ return artifactKey;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/MavenPropertiesIdentifier.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/MavenPropertiesIdentifier.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/MavenPropertiesIdentifier.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,72 @@
+package org.jboss.tools.maven.sourcelookup.internal.identification;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
+
+public class MavenPropertiesIdentifier implements ArtifactIdentifier {
+
+ @Override
+ public ArtifactKey identify(File file) throws CoreException {
+ ZipFile jar;
+ try {
+// try {
+// Random r = new Random();
+// Thread.sleep(r.nextInt(10)*1000);
+// } catch (InterruptedException e) {
+// }
+ jar = new ZipFile(file);
+ return getArtifactFromMetaInf(jar);
+ } catch (ZipException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ protected static ArtifactKey getArtifactFromMetaInf(ZipFile jar) throws IOException {
+ ZipEntry mavenEntry = jar.getEntry("META-INF/maven");//$NON-NLS-1$
+ if (mavenEntry == null) {
+ return null;
+ }
+ String entryName = mavenEntry.getName();
+ Enumeration<? extends ZipEntry> zipEntries = jar.entries();
+ ArtifactKey artifact = null;
+
+
+ while (zipEntries.hasMoreElements()) {
+ ZipEntry zipEntry = zipEntries.nextElement();
+ if (zipEntry.getName().endsWith("pom.properties")
+ && zipEntry.getName().startsWith(entryName)) {
+ if (artifact != null) {
+ //org.fusesource.jansi:jansi:1.6 is an OSGi bundle containing several maven pom files.
+ //The first properties being found is wrong.
+ //So for the moment we bail but should try to look at the MANIFEST.MF
+ return null;
+ }
+ Properties props = new Properties();
+ props.load(jar.getInputStream(zipEntry));
+ String groupId = props.getProperty("groupId");
+ String artifactId = props.getProperty("artifactId");
+ String version = props.getProperty("version");
+ String classifier = props.getProperty("classifier");
+ if (groupId != null && artifactId != null && version != null) {
+ artifact = new ArtifactKey(groupId, artifactId, version,
+ classifier);
+ }
+ }
+ }
+
+ return artifact;
+ }
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusIndexIdentifier.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusIndexIdentifier.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusIndexIdentifier.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,74 @@
+package org.jboss.tools.maven.sourcelookup.internal.identification;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.internal.index.IIndex;
+import org.eclipse.m2e.core.internal.index.IndexManager;
+import org.eclipse.m2e.core.internal.index.IndexedArtifactFile;
+import org.eclipse.m2e.core.internal.index.nexus.NexusIndex;
+import org.eclipse.m2e.core.internal.index.nexus.NexusIndexManager;
+import org.eclipse.m2e.core.repository.IRepository;
+import org.eclipse.m2e.core.repository.IRepositoryRegistry;
+import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
+
+@SuppressWarnings("restriction")
+public class NexusIndexIdentifier implements ArtifactIdentifier {
+
+ private List<IRepository> globalRepositories;
+
+ public NexusIndexIdentifier() {
+ globalRepositories = initGlobalRepositories();
+ }
+
+ @Override
+ public ArtifactKey identify(File file) throws CoreException {
+ IndexManager indexManager = MavenPlugin.getIndexManager();
+ IIndex index = indexManager.getAllIndexes();
+ IndexedArtifactFile info = null;
+ try {
+ info = index.identify(file);
+ } catch (Throwable e) {
+ // ignore
+ }
+ ArtifactKey artifact = null;
+ if (info != null) {
+ artifact = info.getArtifactKey();
+ if (artifact != null) {
+ return artifact;
+ }
+ }
+ if (indexManager instanceof NexusIndexManager) {
+ NexusIndexManager nexusIndexManager = (NexusIndexManager) indexManager;
+ for (IRepository repository : globalRepositories) {
+ NexusIndex nexusIndex = nexusIndexManager.getIndex(repository);
+ if (nexusIndex != null) {
+ try {
+ info = nexusIndex.identify(file);
+ } catch (Throwable t) {
+ // ignore
+ }
+ if (info != null) {
+ artifact = info.getArtifactKey();
+ if (artifact != null) {
+ return artifact;
+ }
+ }
+ }
+ }
+ }
+ return artifact;
+ }
+
+ private List<IRepository> initGlobalRepositories() {
+ IRepositoryRegistry repositoryRegistry = MavenPlugin.getRepositoryRegistry();
+ List<IRepository> repositories = repositoryRegistry.
+ getRepositories(IRepositoryRegistry.SCOPE_SETTINGS);
+ return repositories == null? Collections.<IRepository>emptyList():repositories;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusRepositoryIdentifier.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusRepositoryIdentifier.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusRepositoryIdentifier.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,148 @@
+package org.jboss.tools.maven.sourcelookup.internal.identification;
+
+import static org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil.getSHA1;
+import static org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil.getSourcesClassifier;
+
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.jboss.tools.maven.sourcelookup.NexusRepository;
+import org.jboss.tools.maven.sourcelookup.SourceLookupActivator;
+import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
+import org.sonatype.nexus.rest.model.NexusArtifact;
+import org.sonatype.nexus.rest.model.SearchResponse;
+
+public class NexusRepositoryIdentifier implements ArtifactIdentifier {
+
+ private static final String PATH_SEPARATOR = "/";
+
+ @Override
+ public ArtifactKey identify(File file) throws CoreException {
+ return getArtifactFromRemoteNexusRepository(file);
+ }
+
+ private static ArtifactKey getArtifactFromRemoteNexusRepository(File file) {
+ String sha1;
+ try {
+ sha1 = getSHA1(file);
+ } catch (Exception e) {
+ return null;
+ }
+ Set<NexusRepository> nexusRepositories = SourceLookupActivator
+ .getNexusRepositories();
+ for (NexusRepository repository : nexusRepositories) {
+ if (!repository.isEnabled()) {
+ continue;
+ }
+ ArtifactKey key = getArtifactFromRemoteNexusRepository(sha1, repository);
+ if (key != null) {
+ ArtifactKey sourcesArtifact = new ArtifactKey(
+ key.getGroupId(), key.getArtifactId(),
+ key.getVersion(),
+ getSourcesClassifier(key.getClassifier()));
+ ArtifactKey resolvedKey = getSourcesArtifactFromJBossNexusRepository(sourcesArtifact, repository);
+ if (resolvedKey != null) {
+ return key;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static ArtifactKey getArtifactFromRemoteNexusRepository(String sha1,
+ NexusRepository nexusRepository) {
+ if (sha1 == null || nexusRepository == null || nexusRepository.getUrl() == null) {
+ return null;
+ }
+ HttpURLConnection connection = null;
+ try {
+ String base = nexusRepository.getUrl();
+ if (!base.endsWith(PATH_SEPARATOR)) {
+ base = base + PATH_SEPARATOR;
+ }
+ // String url =
+ // "https://repository.jboss.org/nexus/service/local/data_index?sha1=";
+ String url = base + "service/local/data_index?sha1=";
+ url = url + URLEncoder.encode(sha1, "UTF-8");
+ JAXBContext context = JAXBContext.newInstance(SearchResponse.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ connection = (HttpURLConnection) new URL(url).openConnection();
+ connection.connect();
+ Object object = unmarshaller.unmarshal(connection.getInputStream());
+ if (object instanceof SearchResponse) {
+ SearchResponse searchResponse = (SearchResponse) object;
+ for (NexusArtifact nexusArtifact : searchResponse.getData()) {
+ String groupId = nexusArtifact.getGroupId();
+ String artifactId = nexusArtifact.getArtifactId();
+ String version = nexusArtifact.getVersion();
+ String classifier = nexusArtifact.getClassifier();
+ ArtifactKey artifact = new ArtifactKey(groupId, artifactId,
+ version, classifier);
+ return artifact;
+ }
+ }
+ } catch (Exception e) {
+ return null;
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return null;
+ }
+
+ private static ArtifactKey getSourcesArtifactFromJBossNexusRepository(ArtifactKey key,
+ NexusRepository nexusRepository) {
+ if (key == null || nexusRepository == null
+ || nexusRepository.getUrl() == null) {
+ return null;
+ }
+ HttpURLConnection connection = null;
+ try {
+ String base = nexusRepository.getUrl();
+ if (!base.endsWith(PATH_SEPARATOR)) {
+ base = base + PATH_SEPARATOR;
+ }
+ // String url =
+ // "https://repository.jboss.org/nexus/service/local/data_index?g=groupId&a=a...";
+ String url = base + "service/local/data_index?";
+ url= url + "g=" + URLEncoder.encode(key.getGroupId(), "UTF-8") + "&";
+ url= url + "a=" + URLEncoder.encode(key.getArtifactId(), "UTF-8") + "&";
+ url= url + "v=" + URLEncoder.encode(key.getVersion(), "UTF-8") + "&";
+ url= url + "c=" + URLEncoder.encode(key.getClassifier(), "UTF-8");
+ JAXBContext context = JAXBContext.newInstance(SearchResponse.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ connection = (HttpURLConnection) new URL(url).openConnection();
+ connection.connect();
+ Object object = unmarshaller.unmarshal(connection.getInputStream());
+ if (object instanceof SearchResponse) {
+ SearchResponse searchResponse = (SearchResponse) object;
+ for (NexusArtifact nexusArtifact : searchResponse.getData()) {
+ String groupId = nexusArtifact.getGroupId();
+ String artifactId = nexusArtifact.getArtifactId();
+ String version = nexusArtifact.getVersion();
+ String classifier = nexusArtifact.getClassifier();
+ ArtifactKey artifact = new ArtifactKey(groupId, artifactId,
+ version, classifier);
+ return artifact;
+ }
+ }
+ } catch (Exception e) {
+ return null;
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return null;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/.settings/org.eclipse.m2e.core.prefs
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/.settings/org.eclipse.m2e.core.prefs (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/.settings/org.eclipse.m2e.core.prefs 2012-07-24 16:31:18 UTC (rev 42693)
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Modified: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java 2012-07-24 16:02:08 UTC (rev 42692)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java 2012-07-24 16:31:18 UTC (rev 42693)
@@ -11,7 +11,6 @@
package org.jboss.tools.maven.sourcelookup.ui.actions;
import java.io.File;
-import java.util.zip.ZipFile;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -40,6 +39,8 @@
import org.eclipse.ui.IEditorPart;
import org.jboss.tools.maven.sourcelookup.SourceLookupActivator;
import org.jboss.tools.maven.sourcelookup.containers.JBossSourceContainer;
+import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
+import org.jboss.tools.maven.sourcelookup.internal.identification.FileIdentificationManager;
import org.jboss.tools.maven.sourcelookup.ui.SourceLookupUIActivator;
/**
@@ -78,8 +79,8 @@
if (fragment.isArchive()) {
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(fragment.getPath());
File file = iFile == null || iFile.getLocation() == null ? fragment.getPath().toFile() : iFile.getLocation().toFile();
- ZipFile jar = new ZipFile(file);
- final ArtifactKey artifact = JBossSourceContainer.getArtifact(file, jar);
+ IFileIdentificationManager identificationManager = new FileIdentificationManager();
+ final ArtifactKey artifact = identificationManager.identify(file, new NullProgressMonitor());
if (artifact != null) {
IPath sourcePath = JBossSourceContainer.getSourcePath(artifact);
if (sourcePath == null || !sourcePath.toFile().exists()) {
13 years, 5 months
JBoss Tools SVN: r42692 - in trunk/vpe/plugins: org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences and 3 other directories.
by jbosstools-commits@lists.jboss.org
Author: dmaliarevich
Date: 2012-07-24 12:02:08 -0400 (Tue, 24 Jul 2012)
New Revision: 42692
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorFieldEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorSelector.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpePreferencesPage.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-8631 - adding an option for border color.
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2012-07-24 14:02:16 UTC (rev 42691)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2012-07-24 16:02:08 UTC (rev 42692)
@@ -18,6 +18,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.resource.StringConverter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlEvent;
@@ -27,6 +28,7 @@
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -76,6 +78,7 @@
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.mozilla.MozillaPreview;
import org.jboss.tools.vpe.editor.mozilla.listener.EditorLoadWindowListener;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.jboss.tools.vpe.editor.xpl.CustomSashForm;
import org.jboss.tools.vpe.editor.xpl.CustomSashForm.ICustomSashFormListener;
import org.jboss.tools.vpe.editor.xpl.EditorSettings;
@@ -1113,9 +1116,8 @@
*/
if (getController() != null) {
boolean doVisualRefresh = false;
- boolean presfShowBorderForUnknownTags = JspEditorPlugin.getDefault()
- .getPreferenceStore().getBoolean(
- IVpePreferencesPage.SHOW_BORDER_FOR_UNKNOWN_TAGS);
+ boolean presfShowBorderForUnknownTags = JspEditorPlugin.getDefault().getPreferenceStore()
+ .getBoolean(IVpePreferencesPage.SHOW_BORDER_FOR_UNKNOWN_TAGS);
if (presfShowBorderForUnknownTags != getController().getVisualBuilder().isShowBorderForUnknownTags()) {
/*
* Templates should be rebuild.
@@ -1124,13 +1126,21 @@
doVisualRefresh = true;
}
+ RGB rgb = StringConverter.asRGB(JspEditorPlugin.getDefault().getPreferenceStore()
+ .getString(IVpePreferencesPage.SELECTION_VISIBLE_BORDER_COLOR));
+ visualEditor.getXulRunnerEditor().setVisibleSelectedElementColor(VpeStyleUtil.rgbToString(rgb));
+
+ rgb = StringConverter.asRGB(JspEditorPlugin.getDefault().getPreferenceStore()
+ .getString(IVpePreferencesPage.SELECTION_HIDDEN_BORDER_COLOR));
+ visualEditor.getXulRunnerEditor().setHiddenSelectedElementColor(VpeStyleUtil.rgbToString(rgb));
+
// if (presfShowSelectionBar != selectionBar.isVisible()) {
// selectionBar.setVisible(presfShowSelectionBar);
// doVisualRefresh = true;
// }
- boolean prefsShowNonVisualTags = JspEditorPlugin.getDefault().getPreferenceStore().
- getBoolean(IVpePreferencesPage.SHOW_NON_VISUAL_TAGS);
+ boolean prefsShowNonVisualTags = JspEditorPlugin.getDefault().getPreferenceStore()
+ .getBoolean(IVpePreferencesPage.SHOW_NON_VISUAL_TAGS);
if (prefsShowNonVisualTags != getController().getVisualBuilder().isShowInvisibleTags()) {
getController().getVisualBuilder().setShowInvisibleTags(prefsShowNonVisualTags);
doVisualRefresh = true;
Added: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorFieldEditor.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorFieldEditor.java (rev 0)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorFieldEditor.java 2012-07-24 16:02:08 UTC (rev 42692)
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.preferences;
+
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * A field editor for a color type preference.
+ */
+public class VpeColorFieldEditor extends FieldEditor {
+
+ /**
+ * The color selector, or <code>null</code> if none.
+ */
+ private VpeColorSelector colorSelector;
+
+ /**
+ * Creates a new color field editor
+ */
+ protected VpeColorFieldEditor() {
+ //No default behavior
+ }
+
+ /**
+ * Creates a color field editor.
+ *
+ * @param name
+ * the name of the preference this field editor works on
+ * @param labelText
+ * the label text of the field editor
+ * @param parent
+ * the parent of the field editor's control
+ */
+ public VpeColorFieldEditor(String name, String labelText, Composite parent) {
+ super(name, labelText, parent);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on FieldEditor.
+ */
+ protected void adjustForNumColumns(int numColumns) {
+ ((GridData) colorSelector.getButton().getLayoutData()).horizontalSpan = numColumns - 1;
+ }
+
+ /**
+ * Computes the size of the color image displayed on the button.
+ * <p>
+ * This is an internal method and should not be called by clients.
+ * </p>
+ *
+ * @param window
+ * the window to create a GC on for calculation.
+ * @return Point The image size
+ *
+ */
+ protected Point computeImageSize(Control window) {
+ // Make the image height as high as a corresponding character. This
+ // makes sure that the button has the same size as a "normal" text
+ // button.
+ GC gc = new GC(window);
+ Font f = JFaceResources.getFontRegistry().get(
+ JFaceResources.DEFAULT_FONT);
+ gc.setFont(f);
+ int height = gc.getFontMetrics().getHeight();
+ gc.dispose();
+ Point p = new Point(height * 3 - 6, height);
+ return p;
+ }
+
+ @Override
+ protected void createControl(Composite parent) {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.horizontalSpacing = HORIZONTAL_GAP;
+ /*
+ * Create only 1 top control
+ */
+ Composite container = new Composite(parent, SWT.NONE);
+ container.setLayout(layout);
+ doFillIntoGrid(container, layout.numColumns);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(org.eclipse.swt.widgets.Composite, int)
+ */
+ protected void doFillIntoGrid(Composite parent, int numColumns) {
+ Control control = getLabelControl(parent);
+ control.setLayoutData(new GridData());
+
+ Button colorButton = getChangeControl(parent);
+ colorButton.setLayoutData(new GridData());
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.FieldEditor#doLoad()
+ */
+ protected void doLoad() {
+ if (colorSelector == null) {
+ return;
+ }
+ colorSelector.setColorValue(PreferenceConverter.getColor(
+ getPreferenceStore(), getPreferenceName()));
+ }
+
+ /*
+ * (non-Javadoc) Method declared on FieldEditor.
+ */
+ protected void doLoadDefault() {
+ if (colorSelector == null) {
+ return;
+ }
+ colorSelector.setColorValue(PreferenceConverter.getDefaultColor(
+ getPreferenceStore(), getPreferenceName()));
+ }
+
+ /*
+ * (non-Javadoc) Method declared on FieldEditor.
+ */
+ protected void doStore() {
+ PreferenceConverter.setValue(getPreferenceStore(), getPreferenceName(),
+ colorSelector.getColorValue());
+ }
+
+ /**
+ * Get the color selector used by the receiver.
+ *
+ * @return ColorSelector/
+ */
+ public VpeColorSelector getColorSelector() {
+ return colorSelector;
+ }
+
+ /**
+ * Returns the change button for this field editor.
+ *
+ * @param parent
+ * The control to create the button in if required.
+ * @return the change button
+ */
+ protected Button getChangeControl(Composite parent) {
+ if (colorSelector == null) {
+ colorSelector = new VpeColorSelector(parent);
+ colorSelector.addListener(new IPropertyChangeListener() {
+ // forward the property change of the color selector
+ public void propertyChange(PropertyChangeEvent event) {
+ VpeColorFieldEditor.this.fireValueChanged(event.getProperty(),
+ event.getOldValue(), event.getNewValue());
+ setPresentsDefaultValue(false);
+ }
+ });
+
+ } else {
+ checkParent(colorSelector.getButton(), parent);
+ }
+ return colorSelector.getButton();
+ }
+
+ /*
+ * (non-Javadoc) Method declared on FieldEditor.
+ */
+ public int getNumberOfControls() {
+ return 1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.FieldEditor#setEnabled(boolean,
+ * org.eclipse.swt.widgets.Composite)
+ */
+ public void setEnabled(boolean enabled, Composite parent) {
+ super.setEnabled(enabled, parent);
+ getChangeControl(parent).setEnabled(enabled);
+ }
+
+}
Added: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorSelector.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorSelector.java (rev 0)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpeColorSelector.java 2012-07-24 16:02:08 UTC (rev 42692)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.preferences;
+
+import org.eclipse.jface.preference.ColorSelector;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
+
+public class VpeColorSelector extends ColorSelector {
+
+ private Text colorText;
+
+ public VpeColorSelector(Composite parent) {
+ super(parent);
+ colorText = new Text(parent, SWT.NONE);
+ colorText.setEditable(false);
+ colorText.setTextLimit(9);
+ colorText.setText(VpeStyleUtil.rgbToString(getColorValue()));
+ }
+
+ @Override
+ protected void updateColorImage() {
+ super.updateColorImage();
+ colorText.setText(VpeStyleUtil.rgbToString(getColorValue()));
+ }
+
+ public Text getColorText() {
+ return colorText;
+ }
+
+}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpePreferencesPage.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpePreferencesPage.java 2012-07-24 14:02:16 UTC (rev 42691)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/VpePreferencesPage.java 2012-07-24 16:02:08 UTC (rev 42692)
@@ -142,6 +142,12 @@
addField(new VpeBooleanFieldEditor(SHOW_RESOURCE_BUNDLES_USAGE_AS_EL,
VpeUIMessages.SHOW_RESOURCE_BUNDLES_USAGE_AS_EL,
visualAppearanceGroup));
+
+ addField(new VpeColorFieldEditor(SELECTION_VISIBLE_BORDER_COLOR,
+ VpeUIMessages.SELECTION_VISIBLE_BORDER_COLOR, visualAppearanceGroup));
+ addField(new VpeColorFieldEditor(SELECTION_HIDDEN_BORDER_COLOR,
+ VpeUIMessages.SELECTION_HIDDEN_BORDER_COLOR, visualAppearanceGroup));
+
addField(new VpeBooleanFieldEditor(ASK_TAG_ATTRIBUTES_ON_TAG_INSERT,
VpeUIMessages.ASK_TAG_ATTRIBUTES_ON_TAG_INSERT,
confirmationGroup));
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2012-07-24 14:02:16 UTC (rev 42691)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2012-07-24 16:02:08 UTC (rev 42692)
@@ -30,6 +30,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.ILocationProvider;
@@ -973,4 +974,29 @@
}
return cssBuilder.toString();
}
+
+ /**
+ * Method for convert RGB to String
+ *
+ * @param rgb RGB color
+ * @return String color
+ */
+ public static String rgbToString(RGB rgb) {
+ String colorStr = "#0000FF"; //$NON-NLS-1$
+ if (rgb != null) {
+ colorStr = "#" //$NON-NLS-1$
+ + (rgb.red < 10 ? "0" : Constants.EMPTY) //$NON-NLS-1$
+ + Integer.toHexString(rgb.red)
+ + (rgb.green < 10 ? "0" : Constants.EMPTY) //$NON-NLS-1$
+ + Integer.toHexString(rgb.green)
+ + Constants.EMPTY
+ + (rgb.blue < 10 ? "0" : Constants.EMPTY) //$NON-NLS-1$
+ + Integer.toHexString(rgb.blue);
+ colorStr = colorStr.toUpperCase();
+ } else {
+ VpePlugin.getDefault().logError("Cannot convert RGB color to string, because it is null"); //$NON-NLS-1$
+ }
+ return colorStr;
+ }
+ // org.jboss.tools.jst.css.dialog.common.Util.getColor(..)
}
\ No newline at end of file
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2012-07-24 14:02:16 UTC (rev 42691)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2012-07-24 16:02:08 UTC (rev 42692)
@@ -134,6 +134,8 @@
public static String SHOW_RESOURCE_BUNDLES_USAGE_AS_EL;
public static String SHOW_BUNDLES_AS_EL;
public static String SHOW_BUNDLES_AS_MESSAGES;
+ public static String SELECTION_VISIBLE_BORDER_COLOR;
+ public static String SELECTION_HIDDEN_BORDER_COLOR;
public static String ASK_TAG_ATTRIBUTES_ON_TAG_INSERT;
public static String INFORM_WHEN_PROJECT_MIGHT_NOT_BE_CONFIGURED_PROPERLY_FOR_VPE;
public static String DEFAULT_VPE_TAB;
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2012-07-24 14:02:16 UTC (rev 42691)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2012-07-24 16:02:08 UTC (rev 42692)
@@ -118,6 +118,8 @@
SHOW_TEXT_FORMATTING = Show text formatting bar
HIDE_TEXT_FORMATTING = Hide text formatting bar
SHOW_RESOURCE_BUNDLES_USAGE_AS_EL=Show resource bundles usage as EL expressions
+SELECTION_VISIBLE_BORDER_COLOR=Selection border color for visible element:\t
+SELECTION_HIDDEN_BORDER_COLOR=Selection border color for hidden element:\t
SHOW_BUNDLES_AS_EL=Show bundle's messages as EL expressions
SHOW_BUNDLES_AS_MESSAGES=Show bundle's messages explicitly
ASK_TAG_ATTRIBUTES_ON_TAG_INSERT=Ask for tag attributes during tag insert
Modified: trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java 2012-07-24 14:02:16 UTC (rev 42691)
+++ trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java 2012-07-24 16:02:08 UTC (rev 42692)
@@ -59,14 +59,13 @@
/**
* color which used for highlight elements which user can see, blue color
*/
- private static final String FLASHER_VISUAL_ELEMENT_COLOR = "#0000ff"; //$NON-NLS-1$
+ private static String visibleSelectedElementColor = "#0000ff"; //$NON-NLS-1$
/**
* color which used for highlight parent elements for elements which user,
* red color can't see.
*/
- private static final String FLASHER_HIDDEN_ELEMENT_COLOR = "#ff0000"; //$NON-NLS-1$
-
+ private static String hiddenSelectedElementColor = "#ff0000"; //$NON-NLS-1$
/**
* Contains name of attribute for inIFLasher drawing
*/
@@ -411,18 +410,18 @@
private FlasherData prepareFlasherData(nsIDOMNode domNode){
nsIDOMElement domElement = getElementForNode(domNode);
- String selectionBorderColor = FLASHER_VISUAL_ELEMENT_COLOR;
+ String selectionBorderColor = getVisibleSelectedElementColor();
if (domElement != null) {
if (isVisible(domElement)) {
if (domElement.getAttribute(VPE_INVISIBLE_ELEMENT) == null
|| (!domElement.getAttribute(VPE_INVISIBLE_ELEMENT)
.equals(Boolean.TRUE.toString()))) {
- selectionBorderColor = FLASHER_VISUAL_ELEMENT_COLOR;
+ selectionBorderColor = getVisibleSelectedElementColor();
} else {
- selectionBorderColor = FLASHER_HIDDEN_ELEMENT_COLOR;
+ selectionBorderColor = getHiddenSelectedElementColor();
}
} else {
- selectionBorderColor = FLASHER_HIDDEN_ELEMENT_COLOR;
+ selectionBorderColor = getHiddenSelectedElementColor();
domElement = findVisibleParentElement(domElement);
}
}
@@ -521,4 +520,21 @@
}
return keyboardEvent;
}
+
+ public String getVisibleSelectedElementColor() {
+ return visibleSelectedElementColor;
+ }
+
+ public void setVisibleSelectedElementColor(String visibleSelectedElementColor) {
+ XulRunnerEditor.visibleSelectedElementColor = visibleSelectedElementColor;
+ }
+
+ public String getHiddenSelectedElementColor() {
+ return hiddenSelectedElementColor;
+ }
+
+ public void setHiddenSelectedElementColor(String hiddenSelectedElementColor) {
+ XulRunnerEditor.hiddenSelectedElementColor = hiddenSelectedElementColor;
+ }
+
}
13 years, 5 months