View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   * 
19   * Author: Siamak Haschemi
20   * Contact: haschemi@informatik.hu-berlin.de
21   */
22  package net.sourceforge.osgi.deployment.maven.container;
23  
24  import java.util.ArrayList;
25  import java.util.Iterator;
26  import java.util.List;
27  
28  import net.sourceforge.osgi.deployment.maven.IResource;
29  
30  
31  /**
32   * <p>
33   * This class represents a Deployment-Package and stores some information about it.
34   * </p>
35   * <p>
36   * The resources if a Deployment-Package are categorized in three groups:
37   * <ul>
38   * <li>Bundle-Resources</li>
39   * <li>Localization-Resources</li>
40   * <li>Processed-Resources</li>
41   * </ul>
42   * </p>
43   * 
44   * 
45   * @author Siamak Haschemi, haschemi@informatik.hu-berlin.de
46   */
47  public class DeploymentPackageInfo {
48    private String m_bundleLocalization = null;
49    private String m_symbolicName = null;
50    private String m_copyright = null;
51    private String m_description = null;
52    private String m_version = null;
53    private String m_contactAddress = null;
54    private String m_docURL = null;
55    private String m_vendor = null;
56    private String m_fixPack = null;
57  
58    /**
59     * The resources.
60     * 
61     * @parameter property="resources"
62     */
63    private List< IResource > m_resources = null;
64  
65    /**
66     * A constructor which initializes an instance of a {@link DeploymentPackageInfo}.
67     */
68    public DeploymentPackageInfo() {
69      m_resources = new ArrayList< IResource >();
70    }
71  
72    /**
73     * @return the description
74     */
75    public final String getDescription() {
76      return m_description;
77    }
78  
79    /**
80     * @param p_description
81     *          the description to set
82     */
83    public final void setDescription(final String p_description) {
84      m_description = p_description;
85    }
86  
87    /**
88     * @return the version
89     */
90    public final String getVersion() {
91      return m_version;
92    }
93  
94    /**
95     * @param p_version
96     *          the version to set
97     */
98    public final void setVersion(final String p_version) {
99      m_version = p_version;
100   }
101 
102   /**
103    * @return the copyright
104    */
105   public final String getCopyright() {
106     return m_copyright;
107   }
108 
109   /**
110    * @param p_copyright
111    *          the copyright to set
112    */
113   public final void setCopyright(final String p_copyright) {
114     m_copyright = p_copyright;
115   }
116 
117   /**
118    * @return the contactAddress
119    */
120   public final String getContactAddress() {
121     return m_contactAddress;
122   }
123 
124   /**
125    * @param p_contactAddress
126    *          the contactAddress to set
127    */
128   public final void setContactAddress(final String p_contactAddress) {
129     m_contactAddress = p_contactAddress;
130   }
131 
132   /**
133    * @return the docURL
134    */
135   public final String getDocURL() {
136     return m_docURL;
137   }
138 
139   /**
140    * @param p_docURL
141    *          the docURL to set
142    */
143   public final void setDocURL(final String p_docURL) {
144     m_docURL = p_docURL;
145   }
146 
147   /**
148    * @return the vendor
149    */
150   public final String getVendor() {
151     return m_vendor;
152   }
153 
154   /**
155    * @param p_vendor
156    *          the vendor to set
157    */
158   public final void setVendor(final String p_vendor) {
159     m_vendor = p_vendor;
160   }
161 
162   /**
163    * @return the fixPack
164    */
165   public final String getFixPack() {
166     return m_fixPack;
167   }
168 
169   /**
170    * @param p_fixPack
171    *          the fixPack to set
172    */
173   public final void setFixPack(final String p_fixPack) {
174     m_fixPack = p_fixPack;
175   }
176 
177   /**
178    * @return the resources
179    */
180   public final List< IResource > getResources() {
181     return m_resources;
182   }
183 
184   /**
185    * @param p_resources
186    *          the resources to set
187    */
188   public final void setResources(final List< IResource > p_resources) {
189     m_resources = p_resources;
190   }
191 
192   /**
193    * @return the symbolicName
194    */
195   public final String getSymbolicName() {
196     return m_symbolicName;
197   }
198 
199   /**
200    * @param p_symbolicName
201    *          the symbolicName to set
202    */
203   public final void setSymbolicName(final String p_symbolicName) {
204     m_symbolicName = p_symbolicName;
205   }
206 
207   /**
208    * @return the bundleLocalization
209    */
210   public final String getBundleLocalization() {
211     return m_bundleLocalization;
212   }
213 
214   /**
215    * @param p_bundleLocalization
216    *          the bundleLocalization to set
217    */
218   public final void setBundleLocalization(final String p_bundleLocalization) {
219     m_bundleLocalization = p_bundleLocalization;
220   }
221 
222   /**
223    * Resources can be Bundle-, Localization- or Processed-Resources. This method filters the whole resource list and returns only Bundle-Resources.
224    * 
225    * @return A filtered resource list where only Bundle-Resources are contained.
226    */
227   public final List< BundleResource > getBundleResources() {
228     final List< BundleResource > list = new ArrayList< BundleResource >();
229     for (final IResource resource : m_resources) {
230       if (resource instanceof BundleResource) {
231         list.add((BundleResource) resource);
232       }
233     }
234     return list;
235   }
236 
237   /**
238    * Resources can be Bundle-, Localization- or Processed-Resources. This method filters the whole resource list and returns only Processed-Resources.
239    * 
240    * @return A filtered resource list where only Processed-Resources are contained.
241    */
242   public final List< ProcessedResource > getProcessedResources() {
243     final List< ProcessedResource > list = new ArrayList< ProcessedResource >();
244     for (final IResource resource : m_resources) {
245       if (resource instanceof ProcessedResource) {
246         list.add((ProcessedResource) resource);
247       }
248     }
249 
250     if (m_bundleLocalization != null && m_bundleLocalization.trim().length() >= 0) {
251       for (final Iterator< ProcessedResource > i = list.iterator(); i.hasNext();) {
252         final ProcessedResource processedResource = i.next();
253         if (processedResource.getResourceId().startsWith(m_bundleLocalization)) {
254           i.remove();
255         }
256       }
257     }
258 
259     return list;
260   }
261 
262   /**
263    * Resources can be Bundle-, Localization- or Processed-Resources. This method filters the whole resource list and returns only Localization-Resources.
264    * 
265    * @return A filtered resource list where only Localization-Resources are contained.
266    */
267   public final List< ProcessedResource > getLocalizationResources() {
268     final List< ProcessedResource > list = new ArrayList< ProcessedResource >();
269     if (m_bundleLocalization == null || m_bundleLocalization.trim().length() == 0) {
270       return list;
271     }
272     for (final IResource resource : m_resources) {
273       if (resource instanceof ProcessedResource) {
274         final ProcessedResource resource2 = (ProcessedResource) resource;
275         if (resource2.getResourceId().startsWith(m_bundleLocalization)) {
276           list.add(resource2);
277         }
278       }
279     }
280     return list;
281   }
282 
283 }