KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > registry > xml > LibraryImpl


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2006 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin.registry.xml;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.java.plugin.registry.Library;
28 import org.java.plugin.registry.ManifestProcessingException;
29 import org.java.plugin.registry.Version;
30
31 /**
32  * @version $Id: LibraryImpl.java,v 1.4 2006/06/05 18:16:43 ddimon Exp $
33  */

34 class LibraryImpl extends PluginElementImpl implements Library {
35     private final ModelLibrary model;
36     private List JavaDoc exports; // <String>
37

38     LibraryImpl(final PluginDescriptorImpl descr,
39             final PluginFragmentImpl aFragment, final ModelLibrary aModel)
40             throws ManifestProcessingException {
41         super(descr, aFragment, aModel.getId(), aModel.getDocumentation());
42         model = aModel;
43         if ((model.getPath() == null)
44                 || (model.getPath().trim().length() == 0)) {
45             throw new ManifestProcessingException(
46                     PluginRegistryImpl.PACKAGE_NAME,
47                     "libraryPathIsBlank"); //$NON-NLS-1$
48
}
49         exports = new ArrayList JavaDoc(model.getExports().size());
50         for (Iterator JavaDoc it = model.getExports().iterator(); it.hasNext();) {
51             String JavaDoc exportPrefix = (String JavaDoc) it.next();
52             if ((exportPrefix == null) || (exportPrefix.trim().length() == 0)) {
53                 throw new ManifestProcessingException(
54                         PluginRegistryImpl.PACKAGE_NAME,
55                         "exportPrefixIBlank"); //$NON-NLS-1$
56
}
57             exportPrefix = exportPrefix.replace('\\', '.').replace('/', '.');
58             if (exportPrefix.startsWith(".")) { //$NON-NLS-1$
59
exportPrefix = exportPrefix.substring(1);
60             }
61             exports.add(exportPrefix);
62         }
63         exports = Collections.unmodifiableList(exports);
64         if (log.isDebugEnabled()) {
65             log.debug("object instantiated: " + this); //$NON-NLS-1$
66
}
67     }
68
69     /**
70      * @see org.java.plugin.registry.Library#getPath()
71      */

72     public String JavaDoc getPath() {
73         return model.getPath();
74     }
75
76     /**
77      * @see org.java.plugin.registry.Library#getExports()
78      */

79     public Collection JavaDoc getExports() {
80         return exports;
81     }
82
83     /**
84      * @see org.java.plugin.registry.Library#isCodeLibrary()
85      */

86     public boolean isCodeLibrary() {
87         return model.isCodeLibrary();
88     }
89
90     /**
91      * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
92      */

93     public String JavaDoc getUniqueId() {
94         return getDeclaringPluginDescriptor().getRegistry().makeUniqueId(
95                 getDeclaringPluginDescriptor().getId(), getId());
96     }
97     
98     /**
99      * @see java.lang.Object#toString()
100      */

101     public String JavaDoc toString() {
102         return "{Library: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
103
}
104
105     /**
106      * @see org.java.plugin.registry.Library#getVersion()
107      */

108     public Version getVersion() {
109         return model.getVersion();
110     }
111 }
112
Popular Tags