001: /*****************************************************************************
002: * Java Plug-in Framework (JPF)
003: * Copyright (C) 2004-2007 Dmitry Olshansky
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *****************************************************************************/package org.java.plugin.registry.xml;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.List;
024:
025: import org.java.plugin.registry.Library;
026: import org.java.plugin.registry.ManifestProcessingException;
027: import org.java.plugin.registry.Version;
028:
029: /**
030: * @version $Id$
031: */
032: class LibraryImpl extends PluginElementImpl<Library> implements Library {
033: private final ModelLibrary model;
034: private List<String> exports;
035:
036: LibraryImpl(final PluginDescriptorImpl descr,
037: final PluginFragmentImpl aFragment,
038: final ModelLibrary aModel)
039: throws ManifestProcessingException {
040: super (descr, aFragment, aModel.getId(), aModel
041: .getDocumentation());
042: model = aModel;
043: if ((model.getPath() == null)
044: || (model.getPath().trim().length() == 0)) {
045: throw new ManifestProcessingException(
046: PluginRegistryImpl.PACKAGE_NAME,
047: "libraryPathIsBlank"); //$NON-NLS-1$
048: }
049: exports = new ArrayList<String>(model.getExports().size());
050: for (String exportPrefix : model.getExports()) {
051: if ((exportPrefix == null)
052: || (exportPrefix.trim().length() == 0)) {
053: throw new ManifestProcessingException(
054: PluginRegistryImpl.PACKAGE_NAME,
055: "exportPrefixIBlank"); //$NON-NLS-1$
056: }
057: exportPrefix = exportPrefix.replace('\\', '.').replace('/',
058: '.');
059: if (exportPrefix.startsWith(".")) { //$NON-NLS-1$
060: exportPrefix = exportPrefix.substring(1);
061: }
062: exports.add(exportPrefix);
063: }
064: exports = Collections.unmodifiableList(exports);
065: if (log.isDebugEnabled()) {
066: log.debug("object instantiated: " + this ); //$NON-NLS-1$
067: }
068: }
069:
070: /**
071: * @see org.java.plugin.registry.Library#getPath()
072: */
073: public String getPath() {
074: return model.getPath();
075: }
076:
077: /**
078: * @see org.java.plugin.registry.Library#getExports()
079: */
080: public Collection<String> getExports() {
081: return exports;
082: }
083:
084: /**
085: * @see org.java.plugin.registry.Library#isCodeLibrary()
086: */
087: public boolean isCodeLibrary() {
088: return model.isCodeLibrary();
089: }
090:
091: /**
092: * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
093: */
094: public String getUniqueId() {
095: return getDeclaringPluginDescriptor().getRegistry()
096: .makeUniqueId(getDeclaringPluginDescriptor().getId(),
097: getId());
098: }
099:
100: /**
101: * @see java.lang.Object#toString()
102: */
103: @Override
104: public String toString() {
105: return "{Library: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
106: }
107:
108: /**
109: * @see org.java.plugin.registry.Library#getVersion()
110: */
111: public Version getVersion() {
112: return model.getVersion();
113: }
114: }
|