KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbfreeform > LookupMergerImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbfreeform;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.netbeans.api.java.project.JavaProjectConstants;
26 import org.netbeans.api.project.ant.AntArtifact;
27 import org.netbeans.spi.project.LookupMerger;
28 import org.netbeans.spi.project.ant.AntArtifactProvider;
29 import org.openide.util.Lookup;
30
31 /**
32  * Merges AntArtifactProviders - duplicates all artifacts that have type
33  * ARTIFACT_TYPE_JAR and changes the type to ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE
34  *
35  * @author Milan Kubec
36  */

37 public class LookupMergerImpl implements LookupMerger {
38     
39     public LookupMergerImpl() { }
40     
41     public Class JavaDoc getMergeableClass() {
42         return AntArtifactProvider.class;
43     }
44
45     public Object JavaDoc merge(Lookup lookup) {
46         return new AntArtifactProviderImpl(lookup);
47     }
48     
49     private static class AntArtifactProviderImpl implements AntArtifactProvider {
50         
51         private Lookup lkp;
52         
53         public AntArtifactProviderImpl(Lookup lookup) {
54             this.lkp = lookup;
55         }
56         
57         public AntArtifact[] getBuildArtifacts() {
58             AntArtifactProvider aap = (AntArtifactProvider) lkp.lookup(AntArtifactProvider.class);
59             AntArtifact artifacts[] = aap.getBuildArtifacts();
60             List JavaDoc ejbArtifactList = new ArrayList JavaDoc();
61             for (int i = 0; i < artifacts.length; i++) {
62                 if (artifacts[i].getType().equals(JavaProjectConstants.ARTIFACT_TYPE_JAR)) {
63                     ejbArtifactList.add(new EJBFreeformAntArtifact(artifacts[i]));
64                 }
65             }
66             AntArtifact allArtifacts[] = new AntArtifact[artifacts.length + ejbArtifactList.size()];
67             AntArtifact ejbArtifacts[] = (AntArtifact[]) ejbArtifactList.toArray(new AntArtifact[ejbArtifactList.size()]);
68             System.arraycopy(artifacts, 0, allArtifacts, 0, artifacts.length);
69             System.arraycopy(ejbArtifacts, 0, allArtifacts, artifacts.length, ejbArtifacts.length);
70             return allArtifacts;
71         }
72         
73     }
74     
75 }
76
Popular Tags