You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ej...@apache.org on 2011/02/04 12:11:31 UTC
svn commit: r1067150 - in
/aries/trunk/application/application-modeller/src/main:
java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
resources/org/apache/aries/application/modelling/messages/APPModellingMessages.properties
Author: ejiang
Date: Fri Feb 4 11:11:31 2011
New Revision: 1067150
URL: http://svn.apache.org/viewvc?rev=1067150&view=rev
Log:
ARIES-566: NPE when generating repository.xml for a wrong bundle location
Modified:
aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
aries/trunk/application/application-modeller/src/main/resources/org/apache/aries/application/modelling/messages/APPModellingMessages.properties
Modified: aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java?rev=1067150&r1=1067149&r2=1067150&view=diff
==============================================================================
--- aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java (original)
+++ aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java Fri Feb 4 11:11:31 2011
@@ -48,6 +48,7 @@ import org.apache.aries.application.mode
import org.apache.aries.application.modelling.ParsedServiceElements;
import org.apache.aries.application.modelling.ParserProxy;
import org.apache.aries.application.modelling.internal.BundleBlueprintParser;
+import org.apache.aries.application.modelling.internal.MessageUtil;
import org.apache.aries.application.utils.manifest.BundleManifest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,156 +56,166 @@ import org.slf4j.LoggerFactory;
public class ModelledResourceManagerImpl implements ModelledResourceManager
{
- private Logger _logger = LoggerFactory.getLogger(ModelledResourceManagerImpl.class);
- private ParserProxy _parserProxy;
- private ModellingManager _modellingManager;
-
- public void setModellingManager (ModellingManager m) {
- _modellingManager = m;
- }
-
- public void setParserProxy (ParserProxy p) {
- _parserProxy = p;
- }
- public ParserProxy getParserProxy()
- {
- return _parserProxy;
- }
-
-
-
- /**
- * For a given file, which we know to be a bundle, parse out all the
- * service, reference and reference-list elements. This method will return
- * all such services, including anonymous ones,
- * but should not return indistinguishable duplicates.
- * @param archive CommonArchive. The caller is responsible for closing this afterwards.
- * @return ParsedServiceElementsImpl
- * @throws OpenFailureException
- */
- @Override
- public ParsedServiceElements getServiceElements (IDirectory archive) throws ModellerException {
-
- _logger.debug(LOG_ENTRY,"getServiceElements", archive );
-
- Set<ExportedService> services = new HashSet<ExportedService>();
- Set<ImportedService> references = new HashSet<ImportedService>();
- try {
- Collection<IFile> blueprints = findBlueprints(archive);
- InputStream is = null;
- for (IFile bpFile : blueprints) {
- URL url = bpFile.toURL();
- URLConnection conn = url.openConnection();
- is = conn.getInputStream();
-
- try {
- ParsedServiceElements pse = getParserProxy().parseAllServiceElements(is);
- services.addAll(pse.getServices());
- references.addAll(pse.getReferences());
-
- } finally {
- if (is != null) {
- is.close();
- }
- }
- }
- } catch (URISyntaxException e) {
- ModellerException m = new ModellerException(e);
- _logger.debug(LOG_EXIT, "getServiceElements", m);
- throw m;
- } catch (IOException e) {
- ModellerException m = new ModellerException(e);
- _logger.debug(LOG_EXIT, "getServiceElements", m);
- throw m;
- } catch (Exception e) {
- ModellerException m = new ModellerException(e);
- _logger.debug(LOG_EXIT, "getServiceElements", m);
- throw m;
- }
- ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
- _logger.debug(LOG_EXIT, "getServiceElements", result);
- return result;
- }
-
- @Override
- public ModelledResource getModelledResource(String uri, IDirectory bundle) throws ModellerException{
- _logger.debug(LOG_ENTRY, "getModelledResource", new Object[]{uri, bundle});
- ParsedServiceElements pse = getServiceElements(bundle);
-
- BundleManifest bm = BundleManifest.fromBundle(new File(bundle.toString()));
- Attributes attributes = bm.getRawAttributes();
- ModelledResource mbi;
- try {
- mbi = _modellingManager.getModelledResource(uri, attributes, pse.getReferences(), pse.getServices());
- } catch (InvalidAttributeException iae) {
- throw new ModellerException(iae);
- }
- _logger.debug(LOG_EXIT, "getModelledResource", mbi);
- return mbi;
- }
-
- /**
- * Helper method to pass a single bundle into findBlueprints
- * @param oneBundle a single bundle
- * @return Files for all the blueprint files within the bundle
- * @throws URISyntaxException
- * @throws IOException
- * @throws OpenFailureException
- */
- private Collection<IFile> findBlueprints (IDirectory oneBundle)
- throws IOException, URISyntaxException
- {
- _logger.debug(LOG_ENTRY, "findBlueprints", oneBundle);
- Set<IDirectory> archiveSet = new HashSet<IDirectory>();
- archiveSet.add(oneBundle);
- Collection<IFile> result = findBlueprints (archiveSet);
- _logger.debug(LOG_EXIT, "findBlueprints", result);
- return result;
- }
-
- /**
- * Locate all blueprint xml files located within a set of bundles. Typically, call findApplicationBundles()
- * first to determine which bundles within an EBA fall within the range of the Application-Content header.
- * (See the comment on that method).
- * @param applicationBundles
- * @return A Collection of blue print files
- * @throws URISyntaxException
- * @throws IOException
- * @throws OpenFailureException
- */
- private Collection<IFile> findBlueprints(Collection<IDirectory> applicationBundles)
- throws IOException, URISyntaxException
- {
- _logger.debug(LOG_ENTRY, "findBlueprints", applicationBundles);
- Collection<IFile> blueprints = new ArrayList<IFile>();
- for (IDirectory appBundle : applicationBundles) {
- if (appBundle != null) {
- BundleManifest bundleMf = BundleManifest.fromBundle(appBundle);
- BundleBlueprintParser bpParser = new BundleBlueprintParser(bundleMf);
- List<IFile> files = appBundle.listAllFiles();
- Iterator<IFile> it = files.iterator();
- while (it.hasNext()) {
- IFile file = (IFile) it.next();
- String directoryFullPath = file.getName();
- String directoryName = "";
- String fileName = "";
- if (directoryFullPath.lastIndexOf("/") != -1) {
- directoryName = directoryFullPath.substring(0, directoryFullPath.lastIndexOf("/"));
- fileName = directoryFullPath.substring(directoryFullPath.lastIndexOf("/") + 1);
- } else {
- if (file.isFile()) {
- directoryName="";
- fileName = directoryFullPath;
- }
-
- }
- if (bpParser.isBPFile(directoryName, fileName)) {
- blueprints.add(file);
- }
- }
- }
- }
- _logger.debug(LOG_EXIT, "findBlueprints", blueprints);
- return blueprints;
- }
+ private Logger _logger = LoggerFactory.getLogger(ModelledResourceManagerImpl.class);
+ private ParserProxy _parserProxy;
+ private ModellingManager _modellingManager;
+
+ public void setModellingManager (ModellingManager m) {
+ _modellingManager = m;
+ }
+
+ public void setParserProxy (ParserProxy p) {
+ _parserProxy = p;
+ }
+ public ParserProxy getParserProxy()
+ {
+ return _parserProxy;
+ }
+
+
+
+ /**
+ * For a given file, which we know to be a bundle, parse out all the
+ * service, reference and reference-list elements. This method will return
+ * all such services, including anonymous ones,
+ * but should not return indistinguishable duplicates.
+ * @param archive CommonArchive. The caller is responsible for closing this afterwards.
+ * @return ParsedServiceElementsImpl
+ * @throws OpenFailureException
+ */
+ @Override
+ public ParsedServiceElements getServiceElements (IDirectory archive) throws ModellerException {
+
+ _logger.debug(LOG_ENTRY,"getServiceElements", archive );
+
+ Set<ExportedService> services = new HashSet<ExportedService>();
+ Set<ImportedService> references = new HashSet<ImportedService>();
+ try {
+ Collection<IFile> blueprints = findBlueprints(archive);
+ InputStream is = null;
+ for (IFile bpFile : blueprints) {
+ URL url = bpFile.toURL();
+ URLConnection conn = url.openConnection();
+ is = conn.getInputStream();
+
+ try {
+ ParsedServiceElements pse = getParserProxy().parseAllServiceElements(is);
+ services.addAll(pse.getServices());
+ references.addAll(pse.getReferences());
+
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ }
+ } catch (URISyntaxException e) {
+ ModellerException m = new ModellerException(e);
+ _logger.debug(LOG_EXIT, "getServiceElements", m);
+ throw m;
+ } catch (IOException e) {
+ ModellerException m = new ModellerException(e);
+ _logger.debug(LOG_EXIT, "getServiceElements", m);
+ throw m;
+ } catch (Exception e) {
+ ModellerException m = new ModellerException(e);
+ _logger.debug(LOG_EXIT, "getServiceElements", m);
+ throw m;
+ }
+ ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
+ _logger.debug(LOG_EXIT, "getServiceElements", result);
+ return result;
+ }
+
+ @Override
+ public ModelledResource getModelledResource(String uri, IDirectory bundle) throws ModellerException{
+ _logger.debug(LOG_ENTRY, "getModelledResource", new Object[]{uri, bundle});
+
+ if ((bundle != null) && (new File(bundle.toString()).exists())) {
+ ParsedServiceElements pse = getServiceElements(bundle);
+ BundleManifest bm = BundleManifest.fromBundle(new File(bundle.toString()));
+ Attributes attributes = bm.getRawAttributes();
+ ModelledResource mbi = null;
+ try {
+ mbi = _modellingManager.getModelledResource(uri, attributes, pse.getReferences(), pse.getServices());
+ } catch (InvalidAttributeException iae) {
+ ModellerException me = new ModellerException(iae);
+ _logger.debug(LOG_EXIT, "getModelledResource", me);
+ throw me;
+ }
+ _logger.debug(LOG_EXIT, "getModelledResource", mbi);
+ return mbi;
+ } else {
+ // The bundle does not exist
+ ModellerException me = new ModellerException(MessageUtil.getMessage("INVALID_BUNDLE_LOCATION", bundle));
+ _logger.debug(LOG_EXIT, "getModelledResource", me);
+ throw me;
+ }
+
+ }
+
+ /**
+ * Helper method to pass a single bundle into findBlueprints
+ * @param oneBundle a single bundle
+ * @return Files for all the blueprint files within the bundle
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws OpenFailureException
+ */
+ private Collection<IFile> findBlueprints (IDirectory oneBundle)
+ throws IOException, URISyntaxException
+ {
+ _logger.debug(LOG_ENTRY, "findBlueprints", oneBundle);
+ Set<IDirectory> archiveSet = new HashSet<IDirectory>();
+ archiveSet.add(oneBundle);
+ Collection<IFile> result = findBlueprints (archiveSet);
+ _logger.debug(LOG_EXIT, "findBlueprints", result);
+ return result;
+ }
+
+ /**
+ * Locate all blueprint xml files located within a set of bundles. Typically, call findApplicationBundles()
+ * first to determine which bundles within an EBA fall within the range of the Application-Content header.
+ * (See the comment on that method).
+ * @param applicationBundles
+ * @return A Collection of blue print files
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws OpenFailureException
+ */
+ private Collection<IFile> findBlueprints(Collection<IDirectory> applicationBundles)
+ throws IOException, URISyntaxException
+ {
+ _logger.debug(LOG_ENTRY, "findBlueprints", applicationBundles);
+ Collection<IFile> blueprints = new ArrayList<IFile>();
+ for (IDirectory appBundle : applicationBundles) {
+ if (appBundle != null) {
+ BundleManifest bundleMf = BundleManifest.fromBundle(appBundle);
+ BundleBlueprintParser bpParser = new BundleBlueprintParser(bundleMf);
+ List<IFile> files = appBundle.listAllFiles();
+ Iterator<IFile> it = files.iterator();
+ while (it.hasNext()) {
+ IFile file = (IFile) it.next();
+ String directoryFullPath = file.getName();
+ String directoryName = "";
+ String fileName = "";
+ if (directoryFullPath.lastIndexOf("/") != -1) {
+ directoryName = directoryFullPath.substring(0, directoryFullPath.lastIndexOf("/"));
+ fileName = directoryFullPath.substring(directoryFullPath.lastIndexOf("/") + 1);
+ } else {
+ if (file.isFile()) {
+ directoryName="";
+ fileName = directoryFullPath;
+ }
+
+ }
+ if (bpParser.isBPFile(directoryName, fileName)) {
+ blueprints.add(file);
+ }
+ }
+ }
+ }
+ _logger.debug(LOG_EXIT, "findBlueprints", blueprints);
+ return blueprints;
+ }
}
Modified: aries/trunk/application/application-modeller/src/main/resources/org/apache/aries/application/modelling/messages/APPModellingMessages.properties
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller/src/main/resources/org/apache/aries/application/modelling/messages/APPModellingMessages.properties?rev=1067150&r1=1067149&r2=1067150&view=diff
==============================================================================
--- aries/trunk/application/application-modeller/src/main/resources/org/apache/aries/application/modelling/messages/APPModellingMessages.properties (original)
+++ aries/trunk/application/application-modeller/src/main/resources/org/apache/aries/application/modelling/messages/APPModellingMessages.properties Fri Feb 4 11:11:31 2011
@@ -17,11 +17,12 @@
# under the License.
#
-MORE_THAN_ONE_FRAG_HOST=APPMODELLING0001W: An internal error occurred. A bundle fragment manifest must define exactly one Fragment-Host entry. The following entry was found {0}.
-TOO_MANY_SYM_NAMES=APPMODELLING0002W: An internal error occurred. A bundle manifest must contain exactly one Bundle-SymbolicName entry. The following entry was found {0}.
-INCORRECT_MANDATORY_HEADERS=APPMODELLING0003W: An internal error occurred. A bundle with symbolic name {0} and manifest version {1} was unable to be processed.
-TOO_MANY_CB_SYM_NAMES=APPMODELLING0004W: An internal error occurred. A composite bundle manifest must contain exactly one Bundle-SymbolicName entry. The following entry was found {0}.
-INCORRECT_CB_MANDATORY_HEADERS=APPMODELLING0005W: An internal error occurred. A composite bundle with symbolic name {0} and manifest version {1} was unable to be processed.
-TOO_MANY_FRAG_HOSTS=APPMODELLING0006W: An internal error occurred. A bundle fragment manifest must define exactly one Fragment-Host entry. The following entry was found {0}.
-INCOMPATIBLE_PACKAGE_VERSION_REQUIREMENTS=APPMODELLING0007W: The asset {0} cannot be resolved. It has incompatible version requirements on the following packages: {1}.
-INVALID_PACKAGE_REQUIREMENT_ATTRIBUTES=APPMODELLING0008W: The asset {0} cannot be resolved. The attribute {1} on an import for package {2} cannot be satisfied at deployment.
+MORE_THAN_ONE_FRAG_HOST=APPMODELLING0001E: An internal error occurred. A bundle fragment manifest must define exactly one Fragment-Host entry. The following entry was found {0}.
+TOO_MANY_SYM_NAMES=APPMODELLING0002E: An internal error occurred. A bundle manifest must contain exactly one Bundle-SymbolicName entry. The following entry was found {0}.
+INCORRECT_MANDATORY_HEADERS=APPMODELLING0003E: An internal error occurred. A bundle with symbolic name {0} and manifest version {1} was unable to be processed.
+TOO_MANY_CB_SYM_NAMES=APPMODELLING0004E: An internal error occurred. A composite bundle manifest must contain exactly one Bundle-SymbolicName entry. The following entry was found {0}.
+INCORRECT_CB_MANDATORY_HEADERS=APPMODELLING0005E: An internal error occurred. A composite bundle with symbolic name {0} and manifest version {1} was unable to be processed.
+TOO_MANY_FRAG_HOSTS=APPMODELLING0006E: An internal error occurred. A bundle fragment manifest must define exactly one Fragment-Host entry. The following entry was found {0}.
+INCOMPATIBLE_PACKAGE_VERSION_REQUIREMENTS=APPMODELLING0007E: The asset {0} cannot be resolved. It has incompatible version requirements on the following packages: {1}.
+INVALID_PACKAGE_REQUIREMENT_ATTRIBUTES=APPMODELLING0008E: The asset {0} cannot be resolved. The attribute {1} on an import for package {2} cannot be satisfied at deployment.
+INVALID_BUNDLE_LOCATION=APPMODELLING0009E: The Bundle {0} does not exist.
\ No newline at end of file