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.io.File;
25  
26  import net.sourceforge.osgi.deployment.maven.IDeploymentPluginContext;
27  import net.sourceforge.osgi.deployment.maven.IResource;
28  
29  
30  /**
31   * 
32   * <p>
33   * From the Deployment Admin Specification:
34   * </p>
35   * <p>
36   * A Deployment Package consists of installable <i>resources</i>. Resources are described in the <i>Name sections</i> of the Manifest. They are stored in the
37   * JAR file under a path. This path is called the <i>resource id</i>. Subsets of these resources are the bundles. Bundles are treated differently from the
38   * other resources by the Deployment Admin service.
39   * </p>
40   * 
41   * @author Siamak Haschemi, haschemi@informatik.hu-berlin.de
42   */
43  public class BundleResource implements IResource {
44    private String m_groupId;
45    private String m_artifactId;
46    private String m_version;
47    private boolean m_customizer;
48    private File m_resolvedFile;
49    private String m_targetPath;
50    private IDeploymentPluginContext m_context;
51  
52    /**
53     * Constructor which initializes the instance of the {@link BundleResource}.
54     */
55    public BundleResource() {
56      m_groupId = null;
57      m_artifactId = null;
58      m_version = null;
59      m_customizer = false;
60      m_resolvedFile = null;
61      m_targetPath = null;
62      m_context = null;
63    }
64  
65    /**
66     * @param p_context
67     *          the context to set
68     */
69    public final void setDeploymentContext(final IDeploymentPluginContext p_context) {
70      m_context = p_context;
71    }
72  
73    /**
74     * @return the path and the name of the resource
75     * @see net.sourceforge.osgi.deployment.maven.IResource#getResourceId()
76     */
77    public final String getResourceId() {
78      if (m_resolvedFile == null) {
79        m_resolvedFile = m_context.resolveResource(m_groupId, m_artifactId, m_version);
80      }
81      String resourceId = m_resolvedFile.getName();
82      if (m_targetPath != null && m_targetPath.length() > 0) {
83        resourceId = m_targetPath + "/" + resourceId;
84      }
85      return resourceId;
86    }
87  
88    /**
89     * @return the targetPath
90     */
91    public final String getTargetPath() {
92      return m_targetPath;
93    }
94  
95    /**
96     * @param p_targetPath
97     *          the targetPath to set
98     */
99    public final void setTargetPath(final String p_targetPath) {
100     m_targetPath = p_targetPath;
101   }
102 
103   /**
104    * @return the customizer
105    */
106   public final boolean isCustomizer() {
107     return m_customizer;
108   }
109 
110   /**
111    * @param p_customizer
112    *          the customizer to set
113    */
114   public final void setCustomizer(final boolean p_customizer) {
115     m_customizer = p_customizer;
116   }
117 
118   /**
119    * @return the groupId
120    */
121   public final String getGroupId() {
122     return m_groupId;
123   }
124 
125   /**
126    * @param p_groupId
127    *          the groupId to set
128    */
129   public final void setGroupId(final String p_groupId) {
130     m_groupId = p_groupId;
131   }
132 
133   /**
134    * @return the artifactId
135    */
136   public final String getArtifactId() {
137     return m_artifactId;
138   }
139 
140   /**
141    * @param p_artifactId
142    *          the artifactId to set
143    */
144   public final void setArtifactId(final String p_artifactId) {
145     m_artifactId = p_artifactId;
146   }
147 
148   /**
149    * @return the version
150    */
151   public final String getVersion() {
152     return m_version;
153   }
154 
155   /**
156    * @param p_version
157    *          the version to set
158    */
159   public final void setVersion(final String p_version) {
160     m_version = p_version;
161   }
162 
163   /**
164    * @return the context
165    */
166   public final IDeploymentPluginContext getContext() {
167     return m_context;
168   }
169 
170   /**
171    * @param p_context
172    *          the context to set
173    */
174   public final void setContext(final IDeploymentPluginContext p_context) {
175     m_context = p_context;
176   }
177 
178   /**
179    * @return the resolvedFile
180    */
181   public final File getResolvedFile() {
182     if (m_resolvedFile == null) {
183       m_resolvedFile = m_context.resolveResource(m_groupId, m_artifactId, m_version);
184     }
185     return m_resolvedFile;
186   }
187 
188   /**
189    * @param p_resolvedFile
190    *          the resolvedFile to set
191    */
192   public final void setResolvedFile(final File p_resolvedFile) {
193     m_resolvedFile = p_resolvedFile;
194   }
195 
196   /**
197    * @see java.lang.Object#toString()
198    * @return a string representation of a {@link BundleResource}.
199    */
200   public final String toString() {
201     final StringBuffer buffer = new StringBuffer(this.getClass().getName());
202     buffer.append("[");
203     buffer.append("groupId:");
204     buffer.append(getGroupId());
205     buffer.append(", ");
206     buffer.append("artifactId:");
207     buffer.append(getArtifactId());
208     buffer.append(", ");
209     buffer.append("version:");
210     buffer.append(getVersion());
211     buffer.append(", ");
212     buffer.append("resolvedFile:");
213     buffer.append(getResolvedFile());
214     buffer.append("]");
215     return buffer.toString();
216   }
217 }