# HG changeset patch # User Girish Patil # Date 1217642239 25200 # Node ID bef05ac24f6cbe401a2d5f98e3c81c26b8ad33c3 # Parent 884837da65c94737edbc32a3f037869a2bcd259c #135917 Code completion for schema w/o TNS. Change is present in 6.5, need to patched in 6.1 diff -r 884837da65c9 -r bef05ac24f6c xml.jaxb/src/org/netbeans/modules/xml/jaxb/cfg/schema/Schema.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/cfg/schema/Schema.java Fri Aug 01 14:34:35 2008 +0200 +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/cfg/schema/Schema.java Fri Aug 01 18:57:19 2008 -0700 @@ -641,6 +641,7 @@ + diff -r 884837da65c9 -r bef05ac24f6c xml.jaxb/src/org/netbeans/modules/xml/jaxb/cfg/schema/Schemas.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/cfg/schema/Schemas.java Fri Aug 01 14:34:35 2008 +0200 +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/cfg/schema/Schemas.java Fri Aug 01 18:57:19 2008 -0700 @@ -50,6 +50,7 @@ * schemas : Schemas * [attr: destdir CDATA #IMPLIED : java.lang.String] * [attr: projectName CDATA #IMPLIED : java.lang.String] + * [attr: version CDATA #IMPLIED : java.math.BigDecimal] * schema : Schema[0,n] * [attr: type CDATA #IMPLIED : java.lang.String] * [attr: package CDATA #IMPLIED : java.lang.String] @@ -79,10 +80,12 @@ public class Schemas { public static final String DESTDIR = "Destdir"; // NOI18N public static final String PROJECTNAME = "ProjectName"; // NOI18N + public static final String VERSION = "Version"; // NOI18N public static final String SCHEMA = "Schema"; // NOI18N private java.lang.String _Destdir; private java.lang.String _ProjectName; + private java.math.BigDecimal _Version; private java.util.List _Schema = new java.util.ArrayList(); // List private java.lang.String schemaLocation; @@ -106,6 +109,7 @@ public Schemas(org.netbeans.modules.xml.jaxb.cfg.schema.Schemas source, boolean justData) { _Destdir = source._Destdir; _ProjectName = source._ProjectName; + _Version = source._Version; for (java.util.Iterator it = source._Schema.iterator(); it.hasNext(); ) { org.netbeans.modules.xml.jaxb.cfg.schema.Schema srcElement = (org.netbeans.modules.xml.jaxb.cfg.schema.Schema)it.next(); @@ -130,6 +134,15 @@ public java.lang.String getProjectName() { return _ProjectName; + } + + // This attribute is optional + public void setVersion(java.math.BigDecimal value) { + _Version = value; + } + + public java.math.BigDecimal getVersion() { + return _Version; } // This attribute is an array, possibly empty @@ -316,6 +329,12 @@ org.netbeans.modules.xml.jaxb.cfg.schema.Schemas.writeXML(out, _ProjectName, true); out.write("'"); // NOI18N } + // version is an attribute with namespace http://xml.netbeans.org/schema/JAXBWizConfig + if (_Version != null) { + out.write(" version='"); + out.write(_Version.toString()); + out.write("'"); // NOI18N + } } protected void writeNodeChildren(java.io.Writer out, String nodeName, String namespace, String indent, java.util.Map namespaceMap) throws java.io.IOException { @@ -444,6 +463,11 @@ attrValue = attr.getValue(); _ProjectName = attrValue; } + attr = (org.w3c.dom.Attr) attrs.getNamedItem("version"); + if (attr != null) { + attrValue = attr.getValue(); + _Version = new java.math.BigDecimal(attrValue); + } } protected void readNodeChildren(org.w3c.dom.Node node, java.util.Map namespacePrefixes) { @@ -514,6 +538,8 @@ setDestdir((java.lang.String)value); else if (name == "projectName") setProjectName((java.lang.String)value); + else if (name == "version") + setVersion((java.math.BigDecimal)value); else if (name == "schema") addSchema((Schema)value); else if (name == "schema[]") @@ -527,6 +553,8 @@ return getDestdir(); if (name == "projectName") return getProjectName(); + if (name == "version") + return getVersion(); if (name == "schema[]") return getSchema(); throw new IllegalArgumentException(name+" is not a valid property name for Schemas"); @@ -600,6 +628,20 @@ } } } + if (childObj instanceof java.math.BigDecimal) { + java.math.BigDecimal child = (java.math.BigDecimal) childObj; + if (child == _Version) { + if (returnConstName) { + return VERSION; + } else if (returnSchemaName) { + return "version"; + } else if (returnXPathName) { + return "@version"; + } else { + return "Version"; + } + } + } return null; } @@ -645,6 +687,9 @@ if (!(_ProjectName == null ? inst._ProjectName == null : _ProjectName.equals(inst._ProjectName))) { return false; } + if (!(_Version == null ? inst._Version == null : _Version.equals(inst._Version))) { + return false; + } if (sizeSchema() != inst.sizeSchema()) return false; // Compare every element. @@ -663,6 +708,7 @@ int result = 17; result = 37*result + (_Destdir == null ? 0 : _Destdir.hashCode()); result = 37*result + (_ProjectName == null ? 0 : _ProjectName.hashCode()); + result = 37*result + (_Version == null ? 0 : _Version.hashCode()); result = 37*result + (_Schema == null ? 0 : _Schema.hashCode()); return result; } @@ -686,6 +732,7 @@ + diff -r 884837da65c9 -r bef05ac24f6c xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBGenSourceClassPathProvider.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBGenSourceClassPathProvider.java Fri Aug 01 14:34:35 2008 +0200 +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBGenSourceClassPathProvider.java Fri Aug 01 18:57:19 2008 -0700 @@ -27,6 +27,7 @@ */ package org.netbeans.modules.xml.jaxb.model; +import java.io.File; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.project.Project; @@ -42,19 +43,22 @@ * @author gpatil */ public class JAXBGenSourceClassPathProvider implements ClassPathProvider { - private static final String JAXB_GEN_SRC_ROOT= - "build/generated/addons/jaxb" ;//NOI18N - + private static final String JAXB_GEN_SRC_ROOT = "/generated/addons/jaxb"; //NOI18N private Project project; private ClassPath sourceCP, compileCP, bootCP; - + private String buildDir = "build" ; //NOI18N + private String jaxbSrcGenDir = buildDir + JAXB_GEN_SRC_ROOT; JAXBGenSourceClassPathProvider(Project project) { this.project = project; + //TODO get/update buildDir, JAXB_SRC_GEN_DIR } public ClassPath findClassPath(FileObject file, String type) { + project.getProjectDirectory().refresh(true); + FileObject clientArtifactsFolder = - project.getProjectDirectory().getFileObject(JAXB_GEN_SRC_ROOT); + project.getProjectDirectory().getFileObject(jaxbSrcGenDir); + if (clientArtifactsFolder != null && (file.equals(clientArtifactsFolder) || FileUtil.isParentOf( clientArtifactsFolder, file))) { diff -r 884837da65c9 -r bef05ac24f6c xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizLookupProvider.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizLookupProvider.java Fri Aug 01 14:34:35 2008 +0200 +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizLookupProvider.java Fri Aug 01 18:57:19 2008 -0700 @@ -44,6 +44,7 @@ JAXBWizModel model = new JAXBWizModelImpl(project); JAXBGenSourceClassPathProvider cpProvider = new JAXBGenSourceClassPathProvider(project); - return Lookups.fixed(new Object[] {model, cpProvider}); + JAXBWizSourceForBinaryQueryImpl sfbq = new JAXBWizSourceForBinaryQueryImpl(); + return Lookups.fixed(new Object[] {model, cpProvider, sfbq}); } } diff -r 884837da65c9 -r bef05ac24f6c xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizSourceForBinaryQueryImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizSourceForBinaryQueryImpl.java Fri Aug 01 18:57:19 2008 -0700 @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ +package org.netbeans.modules.xml.jaxb.model; + +import java.io.File; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.queries.SourceForBinaryQuery; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.modules.xml.jaxb.cfg.schema.Schemas; +import org.netbeans.modules.xml.jaxb.util.ProjectHelper; +import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; + +/** + * + * @author gpatil + */ +public class JAXBWizSourceForBinaryQueryImpl implements SourceForBinaryQueryImplementation { + private final Map cache = new HashMap(); + + public JAXBWizSourceForBinaryQueryImpl(){ + } + + public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { + File archiveFile = FileUtil.archiveOrDirForURL(binaryRoot); + + if (archiveFile != null) { + SourceForBinaryQuery.Result result = cache.get(binaryRoot); + if (result == null) { + Project prj = FileOwnerQuery.getOwner(archiveFile.toURI()); + if (prj != null) { + Schemas scs = ProjectHelper.getXMLBindingSchemas(prj); + if ((scs != null) && (scs.sizeSchema() > 0)){ + result = new Result(prj); + cache.put(binaryRoot, result); + } + } + } + return result; + } + return null; + } + + public class Result implements SourceForBinaryQuery.Result { + + private Project prj; + + public Result(Project prj) { + this.prj = prj; + } + + public FileObject[] getRoots() { + FileObject fo = + prj.getProjectDirectory().getFileObject("build/generated/addons/jaxb"); // NOI18N + return fo == null ? new FileObject[]{} : new FileObject[]{fo}; + } + + public void addChangeListener(ChangeListener l) { + } + + public void removeChangeListener(ChangeListener l) { + } + } +} diff -r 884837da65c9 -r bef05ac24f6c xml.jaxb/src/org/netbeans/modules/xml/jaxb/ui/JAXBWizardIterator.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/ui/JAXBWizardIterator.java Fri Aug 01 14:34:35 2008 +0200 +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/ui/JAXBWizardIterator.java Fri Aug 01 18:57:19 2008 -0700 @@ -172,6 +172,7 @@ String msg = NbBundle.getMessage(JAXBWizardIterator.class, "MSG_ErrorReadingSchema");//NOI18N wiz.putProperty(JAXBWizModuleConstants.WIZ_ERROR_MSG, msg); + project.getProjectDirectory().getFileSystem().refresh(true); throw new IOException(msg); }