diff options
author | pfullbright | 2010-11-15 23:07:41 +0000 |
---|---|---|
committer | pfullbright | 2010-11-15 23:07:41 +0000 |
commit | 03e373f6a83bb39338b2ffa707afd92e9a586356 (patch) | |
tree | 62c7fdf36c02a3a38b82bee072992ae41c87e5b1 /jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb | |
parent | 47292cc4537d5f5faefa99f20bfaf8f3c90bcf7a (diff) | |
download | webtools.dali-03e373f6a83bb39338b2ffa707afd92e9a586356.tar.gz webtools.dali-03e373f6a83bb39338b2ffa707afd92e9a586356.tar.xz webtools.dali-03e373f6a83bb39338b2ffa707afd92e9a586356.zip |
reworked package update
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb')
6 files changed, 224 insertions, 110 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java index 6ca0469e4d..79ec7a28c1 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java @@ -35,4 +35,13 @@ public interface JaxbPackage */ JaxbPackageInfo getPackageInfo(); public final static String PACKAGE_INFO_PROPERTY = "package-info"; //$NON-NLS-1$ + + /** + * Return whether this package has no useful information. + * Useful information includes: + * - annotated package-info.java + * - jaxb.index + * - object factory + */ + boolean isEmpty(); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRootContextNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRootContextNode.java index 7b1bc09ab8..a0387ee10e 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRootContextNode.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRootContextNode.java @@ -25,7 +25,7 @@ public interface JaxbRootContextNode extends JaxbContextNode { /** - * The root context node's packages. + * The set of packages. Includes any package with any interesting JAXB content. * @see #addCollectionChangeListener(String, org.eclipse.jpt.utility.model.listener.CollectionChangeListener) */ Iterable<JaxbPackage> getPackages(); @@ -33,6 +33,14 @@ public interface JaxbRootContextNode int getPackagesSize(); +// /** +// * The set of classes. These may be explicitly or implicitly included. +// */ +// Iterable<JaxbType> getClasses(); +// public final static String CLASSES_COLLECTION = "classes"; //$NON-NLS-1$ +// +// int getClassesSize(); + // // ********** validation ********** // diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbType.java new file mode 100644 index 0000000000..8a0cdf5e5b --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbType.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. 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: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.jaxb.core.context; + +/** + * Represents a java class (/enum/interface) of note. The actual variety of class is indicated by + * the "mapping" (e.g. @XmlType, @XmlRegistry ...) field. + * <p> + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 3.0 + */ +public interface JaxbType + extends JaxbContextNode { + + /** + * The class name. + * This is unchanging in that, if a class name changes, a new JaxbType is created. + */ + String getName(); +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java index 257d96a0eb..1b7eccca4d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java @@ -624,8 +624,58 @@ public abstract class AbstractJaxbProject } - // ********** Java resource persistent type look-up ********** + // ********** Java resource package look-up ********** + + public Iterable<JavaResourcePackage> getJavaResourcePackages(){ + return new FilteringIterable<JavaResourcePackage>( + new TransformationIterable<JaxbFile, JavaResourcePackage>(this.getPackageInfoSourceJaxbFiles()) { + @Override + protected JavaResourcePackage transform(JaxbFile jaxbFile) { + return ((JavaResourcePackageInfoCompilationUnit) jaxbFile.getResourceModel()).getPackage(); + } + }) { + + @Override + protected boolean accept(JavaResourcePackage resourcePackage) { + return resourcePackage != null; + } + }; + } + + public JavaResourcePackage getJavaResourcePackage(String packageName) { + for (JavaResourcePackage jrp : this.getJavaResourcePackages()) { + if (jrp.getName().equals(packageName)) { + return jrp; + } + } + return null; + } + + public Iterable<JavaResourcePackage> getAnnotatedJavaResourcePackages() { + return new FilteringIterable<JavaResourcePackage>(this.getJavaResourcePackages()) { + @Override + protected boolean accept(JavaResourcePackage resourcePackage) { + return resourcePackage.isAnnotated(); // i.e. the package has a valid package annotation + } + }; + } + + public JavaResourcePackage getAnnotatedJavaResourcePackage(String packageName) { + JavaResourcePackage jrp = getJavaResourcePackage(packageName); + return (jrp.isAnnotated()) ? jrp : null; + } + + /** + * return JPA files with package-info source "content" + */ + protected Iterable<JaxbFile> getPackageInfoSourceJaxbFiles() { + return this.getJaxbFiles(JptCorePlugin.JAVA_SOURCE_PACKAGE_INFO_CONTENT_TYPE); + } + + // ********** Java resource type look-up ********** + + public JavaResourceType getJavaResourceType(String typeName) { for (JavaResourceType jrpType : this.getPersistableJavaResourceTypes()) { if (jrpType.getQualifiedName().equals(typeName)) { @@ -682,56 +732,7 @@ public abstract class AbstractJaxbProject ); } - - // ********** Java resource persistent package look-up ********** - - public Iterable<JavaResourcePackage> getJavaResourcePackages(){ - return new FilteringIterable<JavaResourcePackage>( - new TransformationIterable<JaxbFile, JavaResourcePackage>(this.getPackageInfoSourceJaxbFiles()) { - @Override - protected JavaResourcePackage transform(JaxbFile jaxbFile) { - return ((JavaResourcePackageInfoCompilationUnit) jaxbFile.getResourceModel()).getPackage(); - } - }) { - - @Override - protected boolean accept(JavaResourcePackage resourcePackage) { - return resourcePackage != null; - } - }; - } - - public JavaResourcePackage getJavaResourcePackage(String packageName) { - for (JavaResourcePackage jrp : this.getJavaResourcePackages()) { - if (jrp.getName().equals(packageName)) { - return jrp; - } - } - return null; - } - - public Iterable<JavaResourcePackage> getAnnotatedJavaResourcePackages() { - return new FilteringIterable<JavaResourcePackage>(this.getJavaResourcePackages()) { - @Override - protected boolean accept(JavaResourcePackage resourcePackage) { - return resourcePackage.isAnnotated(); // i.e. the package has a valid package annotation - } - }; - } - - public JavaResourcePackage getAnnotatedJavaResourcePackage(String packageName) { - JavaResourcePackage jrp = getJavaResourcePackage(packageName); - return (jrp.isAnnotated()) ? jrp : null; - } - /** - * return JPA files with package-info source "content" - */ - protected Iterable<JaxbFile> getPackageInfoSourceJaxbFiles() { - return this.getJaxbFiles(JptCorePlugin.JAVA_SOURCE_PACKAGE_INFO_CONTENT_TYPE); - } - - // // ********** JARs ********** // // // TODO diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericPackage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericPackage.java index fb5dbd6c5b..886f3a0a9c 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericPackage.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericPackage.java @@ -71,10 +71,15 @@ public class GenericPackage protected void setPackageInfo_(JaxbPackageInfo packageInfo) { JaxbPackageInfo old = this.packageInfo; this.packageInfo = packageInfo; - this.firePropertyChanged(PACKAGE_INFO_PROPERTY, old, this.packageInfo); + firePropertyChanged(PACKAGE_INFO_PROPERTY, old, this.packageInfo); } protected JaxbPackageInfo buildPackageInfo(JavaResourcePackage resourcePackage) { return getFactory().buildJavaPackageInfo(this, resourcePackage); } + + + public boolean isEmpty() { + return getPackageInfo() == null; + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java index 25ab8aec22..af06609c30 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java @@ -9,8 +9,9 @@ ******************************************************************************/ package org.eclipse.jpt.jaxb.core.internal.context; +import java.util.HashMap; import java.util.HashSet; -import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -18,6 +19,10 @@ import org.eclipse.jpt.jaxb.core.JaxbProject; import org.eclipse.jpt.jaxb.core.context.JaxbPackage; import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode; import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; +import org.eclipse.jpt.utility.internal.ClassName; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; +import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; /** * the context model root @@ -29,8 +34,11 @@ public class GenericRootContextNode /* This object has no parent, so it must point to the JAXB project explicitly. */ protected final JaxbProject jaxbProject; - /* Main context objects. */ - protected final PackageContainer packageContainer; + /* The map of package name to JaxbPackage objects */ + protected final Map<String, JaxbPackage> packages; + +// /* The map of class name to JaxbType objects */ +// protected final Map<String, JaxbType> classes; public GenericRootContextNode(JaxbProject jaxbProject) { @@ -39,7 +47,8 @@ public class GenericRootContextNode throw new NullPointerException(); } this.jaxbProject = jaxbProject; - this.packageContainer = new PackageContainer(); + this.packages = new HashMap<String, JaxbPackage>(); +// this.classes = new HashMap<String, JaxbType>(); } @@ -49,11 +58,63 @@ public class GenericRootContextNode } public void synchronizeWithResourceModel() { - this.syncPackages(); + for (JaxbPackage each : getPackages()) { + each.synchronizeWithResourceModel(); + } +// for (JaxbType each : getClasses()) { +// each.synchronizeWithResourceModel(); +// } } public void update() { - this.updatePackages(); + final Set<String> explicitJaxbContextPackageNames = calculateExplicitJaxbContextPackageNames(); + final Set<String> explicitJaxbContextClassNames = calculateExplicitJaxbContextClassNames(); + final Set<String> implicitJaxbContextClassNames = new HashSet<String>(); + + for (String packageName : explicitJaxbContextPackageNames) { + if (! this.packages.containsKey(packageName)) { + addPackage(buildPackage(packageName)); + } + } + + for (String className : explicitJaxbContextClassNames) { + String packageName = ClassName.getPackageName(className); + if (! this.packages.containsKey(packageName)) { + addPackage(buildPackage(packageName)); + } +// if (! this.classes.containsKey(className)) { +// addClass(buildClass(className)); +// } + } + + for (JaxbPackage each : getPackages()) { + each.update(); + } + +// for (JaxbType each : getClasses()) { +// each.update(); +// } + + for (JaxbPackage each : getPackages()) { + if (isEmpty(each)) { + removePackage(each); + } + } + } + + protected Set<String> calculateExplicitJaxbContextPackageNames() { + return CollectionTools.set( + new TransformationIterable<JavaResourcePackage, String>( + getJaxbProject().getAnnotatedJavaResourcePackages()) { + @Override + protected String transform(JavaResourcePackage o) { + return o.getName(); + } + }); + } + + protected Set<String> calculateExplicitJaxbContextClassNames() { + return new HashSet<String>(); } @@ -77,70 +138,67 @@ public class GenericRootContextNode // ************* packages *************** public Iterable<JaxbPackage> getPackages() { - return this.packageContainer.getContextElements(); + return new LiveCloneIterable<JaxbPackage>(this.packages.values()); } public int getPackagesSize() { - return this.packageContainer.getContextElementsSize(); + return this.packages.size(); } - protected JaxbPackage addPackage(JaxbPackage contextPackage, List<JaxbPackage> packages) { - this.addItemToCollection(contextPackage, packages, PACKAGES_COLLECTION); + protected JaxbPackage addPackage(JaxbPackage contextPackage) { + if (this.packages.containsKey(contextPackage.getName())) { + throw new IllegalArgumentException("Package with that name already exists."); + } + this.packages.put(contextPackage.getName(), contextPackage); + fireItemAdded(PACKAGES_COLLECTION, contextPackage); return contextPackage; } - protected void removePackage(JaxbPackage contextPackage, List<JaxbPackage> packages) { - this.removeItemFromCollection(contextPackage, packages, PACKAGES_COLLECTION); - } - - protected void syncPackages() { - this.packageContainer.synchronizeWithResourceModel(); - } - - protected void updatePackages() { - //In this case we need to actually "sync" the list of packages since this is dependent on JaxbFiles - //and an update will be called when jaxb files are added/removed, not a synchronizeWithResourceModel - this.packageContainer.update(); + protected void removePackage(JaxbPackage contextPackage) { + if (! this.packages.containsKey(contextPackage.getName())) { + throw new IllegalArgumentException("No package with that name exists."); + } + this.packages.remove(contextPackage.getName()); + fireItemRemoved(PACKAGES_COLLECTION, contextPackage); } protected JaxbPackage buildPackage(String packageName) { return this.getFactory().buildPackage(this, packageName); } - protected Iterable<String> getPackageNames() { - Set<String> packageNames = new HashSet<String>(); - for (JavaResourcePackage each : getJaxbProject().getAnnotatedJavaResourcePackages()) { - packageNames.add(each.getName()); - } - - return packageNames; - } - - - /** - * package container adapter - */ - protected class PackageContainer - extends CollectionContainer<JaxbPackage, String> { - - @Override - protected String getContextElementsPropertyName() { - return PACKAGES_COLLECTION; - } - - @Override - public JaxbPackage buildContextElement(String packageName) { - return GenericRootContextNode.this.buildPackage(packageName); - } - - @Override - public Iterable<String> getResourceElements() { - return GenericRootContextNode.this.getPackageNames(); - } - - @Override - public String getResourceElement(JaxbPackage jaxbPackage) { - return jaxbPackage.getName(); - } - } + protected boolean isEmpty(JaxbPackage jaxbPackage) { + return jaxbPackage.isEmpty(); + } + + + // ************* classes *************** + +// public Iterable<JaxbType> getClasses() { +// return new LiveCloneIterable<JaxbType>(this.classes.values()); +// } +// +// public int getClassesSize() { +// return this.classes.size(); +// } +// +// protected JaxbType addClass(JaxbType jaxbClass) { +// if (this.classes.containsKey(jaxbClass.getName())) { +// throw new IllegalArgumentException("Class with that name already exists."); +// } +// this.classes.put(jaxbClass.getName(), jaxbClass); +// fireItemAdded(CLASSES_COLLECTION, jaxbClass); +// return jaxbClass; +// } +// +// protected void removeClass(JaxbType jaxbClass) { +// if (! this.classes.containsKey(jaxbClass.getName())) { +// throw new IllegalArgumentException("No class with that name exists."); +// } +// this.classes.remove(jaxbClass.getName()); +// fireItemRemoved(CLASSES_COLLECTION, jaxbClass); +// } +// +// protected JaxbType buildClass(String className) { +// return this.getFactory().buildClass(this, className); +// } } |