Lines 13-19
Link Here
|
13 |
* "Portions Copyrighted [year] [name of copyright owner]" |
13 |
* "Portions Copyrighted [year] [name of copyright owner]" |
14 |
* |
14 |
* |
15 |
* The Original Software is NetBeans. The Initial Developer of the Original |
15 |
* The Original Software is NetBeans. The Initial Developer of the Original |
16 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun |
16 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun |
17 |
* Microsystems, Inc. All Rights Reserved. |
17 |
* Microsystems, Inc. All Rights Reserved. |
18 |
*/ |
18 |
*/ |
19 |
|
19 |
|
Lines 27-32
Link Here
|
27 |
import java.io.OutputStream; |
27 |
import java.io.OutputStream; |
28 |
import java.util.HashMap; |
28 |
import java.util.HashMap; |
29 |
import java.util.HashSet; |
29 |
import java.util.HashSet; |
|
|
30 |
import java.util.LinkedList; |
31 |
import java.util.List; |
30 |
import java.util.Map; |
32 |
import java.util.Map; |
31 |
import java.util.Set; |
33 |
import java.util.Set; |
32 |
import javax.enterprise.deploy.model.DDBean; |
34 |
import javax.enterprise.deploy.model.DDBean; |
Lines 35-47
Link Here
|
35 |
import javax.swing.text.StyledDocument; |
37 |
import javax.swing.text.StyledDocument; |
36 |
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; |
38 |
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; |
37 |
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; |
39 |
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; |
|
|
40 |
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination; |
38 |
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; |
41 |
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; |
39 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration; |
42 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration; |
40 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DeploymentPlanConfiguration; |
43 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DeploymentPlanConfiguration; |
41 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration; |
44 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration; |
42 |
import org.netbeans.modules.j2ee.jboss4.config.gen.EnterpriseBeans; |
45 |
import org.netbeans.modules.j2ee.jboss4.config.gen.EnterpriseBeans; |
|
|
46 |
import org.netbeans.modules.j2ee.jboss4.config.gen.Entity; |
43 |
import org.netbeans.modules.j2ee.jboss4.config.gen.Jboss; |
47 |
import org.netbeans.modules.j2ee.jboss4.config.gen.Jboss; |
44 |
import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDriven; |
48 |
import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDriven; |
|
|
49 |
import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceRef; |
50 |
import org.netbeans.modules.j2ee.jboss4.config.gen.Session; |
45 |
import org.openide.DialogDisplayer; |
51 |
import org.openide.DialogDisplayer; |
46 |
import org.openide.ErrorManager; |
52 |
import org.openide.ErrorManager; |
47 |
import org.openide.NotifyDescriptor; |
53 |
import org.openide.NotifyDescriptor; |
Lines 130-136
Link Here
|
130 |
public boolean supportsCreateDatasource() { |
136 |
public boolean supportsCreateDatasource() { |
131 |
return true; |
137 |
return true; |
132 |
} |
138 |
} |
133 |
|
139 |
|
|
|
140 |
public boolean supportsCreateMessageDestination() { |
141 |
return true; |
142 |
} |
143 |
|
134 |
// //listen on the resource-ref element |
144 |
// //listen on the resource-ref element |
135 |
// deplObj.getDDBeanRoot().addXpathListener(SESSION_RESOURCE_REF, this); |
145 |
// deplObj.getDDBeanRoot().addXpathListener(SESSION_RESOURCE_REF, this); |
136 |
// deplObj.getDDBeanRoot().addXpathListener(ENTITY_RESOURCE_REF, this); |
146 |
// deplObj.getDDBeanRoot().addXpathListener(ENTITY_RESOURCE_REF, this); |
Lines 165-171
Link Here
|
165 |
} else { |
175 |
} else { |
166 |
// create jboss.xml if it does not exist yet |
176 |
// create jboss.xml if it does not exist yet |
167 |
jboss = generateJboss(); |
177 |
jboss = generateJboss(); |
168 |
writefile(jbossFile, jboss); |
178 |
writeFile(jbossFile, jboss); |
169 |
} |
179 |
} |
170 |
} catch (ConfigurationException ce) { |
180 |
} catch (ConfigurationException ce) { |
171 |
ErrorManager.getDefault().notify(ce); |
181 |
ErrorManager.getDefault().notify(ce); |
Lines 237-243
Link Here
|
237 |
// Set beanNames = null; |
247 |
// Set beanNames = null; |
238 |
// if (desc.length > 0 && "javax.sql.DataSource".equals(type[0])) { // NOI18N |
248 |
// if (desc.length > 0 && "javax.sql.DataSource".equals(type[0])) { // NOI18N |
239 |
// beanNames = getRelevantBeansDataRef(desc[0], name[0], eventDDBean.getRoot(), beanType); |
249 |
// beanNames = getRelevantBeansDataRef(desc[0], name[0], eventDDBean.getRoot(), beanType); |
240 |
// addResReference(desc[0], name[0], beanNames, beanType); |
250 |
// String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; |
|
|
251 |
// addResReference(jndiName, name[0], beanNames, beanType); |
241 |
// } |
252 |
// } |
242 |
// else |
253 |
// else |
243 |
// if ("javax.mail.Session".equals(type[0])) { // NOI18N |
254 |
// if ("javax.mail.Session".equals(type[0])) { // NOI18N |
Lines 724-764
Link Here
|
724 |
|
735 |
|
725 |
return beanMap; |
736 |
return beanMap; |
726 |
} |
737 |
} |
|
|
738 |
|
739 |
public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, |
740 |
String referenceName, String jndiName) throws ConfigurationException { |
741 |
|
742 |
Set beanNames = new HashSet(); |
743 |
beanNames.add(ejbName); |
744 |
if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION.equals(ejbType)) { |
745 |
addResReference(jndiName, referenceName, beanNames, BEAN_TYPE.SESSION); |
746 |
} |
747 |
else |
748 |
if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY.equals(ejbType)) { |
749 |
addResReference(jndiName, referenceName, beanNames, BEAN_TYPE.ENTITY); |
750 |
} |
751 |
else |
752 |
if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) { |
753 |
addMsgDrvResReference(jndiName, referenceName, ejbName); |
754 |
} |
755 |
|
756 |
} |
757 |
|
758 |
public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException { |
759 |
|
760 |
EnterpriseBeans beans = getJboss().getEnterpriseBeans(); |
761 |
if (beans == null) { |
762 |
return null; |
763 |
} |
764 |
|
765 |
Session[] sessions = beans.getSession(); |
766 |
for (Session session : sessions) { |
767 |
if (ejbName.equals(session.getEjbName())) { |
768 |
ResourceRef[] resourceRefs = session.getResourceRef(); |
769 |
for (ResourceRef resourceRef : resourceRefs) { |
770 |
String rrn = resourceRef.getResRefName(); |
771 |
if (referenceName.equals(rrn)) { |
772 |
return resourceRef.getJndiName(); |
773 |
} |
774 |
} |
775 |
return null; |
776 |
} |
777 |
} |
778 |
|
779 |
Entity[] entities = beans.getEntity(); |
780 |
for (Entity entity : entities) { |
781 |
if (ejbName.equals(entity.getEjbName())) { |
782 |
ResourceRef[] resourceRefs = entity.getResourceRef(); |
783 |
for (ResourceRef resourceRef : resourceRefs) { |
784 |
String rrn = resourceRef.getResRefName(); |
785 |
if (referenceName.equals(rrn)) { |
786 |
return resourceRef.getJndiName(); |
787 |
} |
788 |
} |
789 |
return null; |
790 |
} |
791 |
} |
792 |
|
793 |
MessageDriven[] mdbs = beans.getMessageDriven(); |
794 |
for (MessageDriven mdb : mdbs) { |
795 |
if (ejbName.equals(mdb.getEjbName())) { |
796 |
ResourceRef[] resourceRefs = mdb.getResourceRef(); |
797 |
for (ResourceRef resourceRef : resourceRefs) { |
798 |
String rrn = resourceRef.getResRefName(); |
799 |
if (referenceName.equals(rrn)) { |
800 |
return resourceRef.getJndiName(); |
801 |
} |
802 |
} |
803 |
return null; |
804 |
} |
805 |
} |
806 |
|
807 |
return null; |
808 |
} |
809 |
|
727 |
|
810 |
|
728 |
/** |
811 |
/** |
729 |
* Add a new data source reference to the beans of the given type without it. |
812 |
* Add a new data source reference to the beans of the given type without it. |
730 |
* |
813 |
* |
731 |
* @param desc data source description |
814 |
* @param jndiName JNDI name of the resource |
732 |
* @param resRefName data source reference name |
815 |
* @param resRefName data source reference name |
733 |
* @param beanNames the beans (ejb-name value) which might need to add data source reference specified by resRefName |
816 |
* @param beanNames the beans (ejb-name value) which might need to add data source reference specified by resRefName |
734 |
* @param beanType type of bean to add data source reference to |
817 |
* @param beanType type of bean to add data source reference to |
735 |
*/ |
818 |
*/ |
736 |
private void addResReference(String desc, final String resRefName, final Set beanNames, final BEAN_TYPE beanType) |
819 |
private void addResReference(final String jndiName, final String resRefName, final Set beanNames, final BEAN_TYPE beanType) |
737 |
throws ConfigurationException |
820 |
throws ConfigurationException |
738 |
{ |
821 |
{ |
739 |
modifyJboss(new JbossModifier() { |
822 |
modifyJboss(new JbossModifier() { |
740 |
public void modify(Jboss modifiedJboss) { |
823 |
public void modify(Jboss modifiedJboss) { |
741 |
String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; |
|
|
742 |
JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); |
824 |
JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName); |
743 |
} |
825 |
} |
744 |
}); |
826 |
}); |
745 |
} |
827 |
} |
746 |
|
828 |
|
747 |
/** |
829 |
/** |
748 |
* Add a new resource reference to the message-driven beans without it. |
830 |
* Add a new resource reference to the message-driven bean. |
749 |
* |
831 |
* |
750 |
* @param desc data source description |
832 |
* @param jndiName JNDI name of the resource |
751 |
* @param resRefName resource reference name |
833 |
* @param resRefName resource reference name |
752 |
* @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link) |
834 |
* @param mdbName the MDB (ejb-name) which might need to add resource reference specified by resRefName |
753 |
* which might need to add resource reference specified by resRefName |
835 |
* which might need to add resource reference specified by resRefName |
754 |
*/ |
836 |
*/ |
755 |
private void addMsgDrvResReference(String desc, final String resRefName, final Map beans) |
837 |
private void addMsgDrvResReference(final String jndiName, final String resRefName, final String mdbName) |
756 |
throws ConfigurationException |
838 |
throws ConfigurationException |
757 |
{ |
839 |
{ |
758 |
modifyJboss(new JbossModifier() { |
840 |
modifyJboss(new JbossModifier() { |
759 |
public void modify(Jboss modifiedJboss) { |
841 |
public void modify(Jboss modifiedJboss) { |
760 |
String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName; |
842 |
JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, mdbName, jndiName); |
761 |
JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); |
|
|
762 |
} |
843 |
} |
763 |
}); |
844 |
}); |
764 |
} |
845 |
} |
Lines 833-845
Link Here
|
833 |
}); |
914 |
}); |
834 |
} |
915 |
} |
835 |
|
916 |
|
|
|
917 |
public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException { |
918 |
addMDB(mdbName, name, type); |
919 |
} |
920 |
|
921 |
public String findMessageDestinationName(String mdbName) throws ConfigurationException { |
922 |
|
923 |
EnterpriseBeans beans = getJboss().getEnterpriseBeans(); |
924 |
if (beans == null) { |
925 |
return null; |
926 |
} |
927 |
|
928 |
MessageDriven[] mdbs = beans.getMessageDriven(); |
929 |
for (MessageDriven mdb : mdbs) { |
930 |
if (mdbName.equals(mdb.getEjbName())) { |
931 |
String destJndiName = mdb.getDestinationJndiName(); |
932 |
if (destJndiName != null) { |
933 |
if (destJndiName.startsWith("queue/") || destJndiName.startsWith("topic/")) { |
934 |
return destJndiName.substring(6); // "queue/".length() == "topic/".length() == 6 |
935 |
} |
936 |
else { |
937 |
ErrorManager.getDefault().log( |
938 |
ErrorManager.INFORMATIONAL, |
939 |
NbBundle.getMessage(EjbDeploymentConfiguration.class, "MSG_NoPrefix", destJndiName)); |
940 |
} |
941 |
} |
942 |
return null; |
943 |
} |
944 |
} |
945 |
|
946 |
return null; |
947 |
} |
948 |
|
836 |
/** |
949 |
/** |
837 |
* Add MDB record. |
950 |
* Add MDB record. |
838 |
* |
951 |
* |
839 |
* @param name MDB name (ejb-name) |
952 |
* @param name MDB name (ejb-name) |
840 |
* @param dest MDB destination (message-destination-link) |
953 |
* @param dest MDB destination (message-destination-link) |
841 |
*/ |
954 |
*/ |
842 |
private void addMDB(final String name, final String dest) throws ConfigurationException { |
955 |
private void addMDB(final String name, final String destName, final MessageDestination.Type destType) |
|
|
956 |
throws ConfigurationException { |
957 |
|
843 |
modifyJboss(new JbossModifier() { |
958 |
modifyJboss(new JbossModifier() { |
844 |
public void modify(Jboss modifiedJboss) { |
959 |
public void modify(Jboss modifiedJboss) { |
845 |
|
960 |
|
Lines 862-868
Link Here
|
862 |
//if it doesn't exist yet, create a new one |
977 |
//if it doesn't exist yet, create a new one |
863 |
MessageDriven mdb = new MessageDriven(); |
978 |
MessageDriven mdb = new MessageDriven(); |
864 |
mdb.setEjbName(name); |
979 |
mdb.setEjbName(name); |
865 |
mdb.setDestinationJndiName(dest); // NOI18N |
980 |
if (MessageDestination.Type.QUEUE.equals(destType)) { |
|
|
981 |
mdb.setDestinationJndiName("queue/" + destName); // NOI18N |
982 |
} |
983 |
else |
984 |
if (MessageDestination.Type.TOPIC.equals(destType)) { |
985 |
mdb.setDestinationJndiName("topic/" + destName); // NOI18N |
986 |
} |
866 |
eb.addMessageDriven(mdb); |
987 |
eb.addMessageDriven(mdb); |
867 |
} |
988 |
} |
868 |
}); |
989 |
}); |
Lines 889-922
Link Here
|
889 |
/** |
1010 |
/** |
890 |
* Add a new connection factory reference to the message-driven beans without it. |
1011 |
* Add a new connection factory reference to the message-driven beans without it. |
891 |
* |
1012 |
* |
892 |
* @param resRefName connection factory reference name |
1013 |
* @param connectionFactoryName connection factory reference name |
893 |
* @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link) |
1014 |
* @param mdbName the MDB (ejb-name) which might need to add connection factory reference specified by resRefName |
894 |
* which might need to add connection factory reference specified by resRefName |
|
|
895 |
*/ |
1015 |
*/ |
896 |
private void addMsgDrvConnectionFactoryReference(final String resRefName, final Map beans) |
1016 |
private void addMsgDrvConnectionFactoryReference(final String connectionFactoryName, final String mdbName) |
897 |
throws ConfigurationException |
1017 |
throws ConfigurationException |
898 |
{ |
1018 |
{ |
899 |
modifyJboss(new JbossModifier() { |
1019 |
modifyJboss(new JbossModifier() { |
900 |
public void modify(Jboss modifiedJboss) { |
1020 |
public void modify(Jboss modifiedJboss) { |
901 |
String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; |
1021 |
String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME; |
902 |
JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName); |
1022 |
JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, connectionFactoryName, mdbName, jndiName); |
903 |
} |
1023 |
} |
904 |
}); |
1024 |
}); |
905 |
} |
1025 |
} |
906 |
|
1026 |
|
|
|
1027 |
public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType, |
1028 |
String referenceName, String connectionFactoryName, |
1029 |
String destName, MessageDestination.Type type) throws ConfigurationException { |
1030 |
|
1031 |
Set beanNames = new HashSet(); |
1032 |
beanNames.add(ejbName); |
1033 |
|
1034 |
String destPrefix = null; |
1035 |
if (MessageDestination.Type.QUEUE.equals(type)) { |
1036 |
destPrefix = "queue/"; |
1037 |
} |
1038 |
else |
1039 |
if (MessageDestination.Type.TOPIC.equals(type)) { |
1040 |
destPrefix = "topic/"; |
1041 |
} |
1042 |
|
1043 |
if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION.equals(ejbType)) { |
1044 |
addConnectionFactoryReference(connectionFactoryName, beanNames, BEAN_TYPE.SESSION); |
1045 |
addMsgDestReference(referenceName, destPrefix, destName, beanNames, BEAN_TYPE.SESSION); |
1046 |
} |
1047 |
else |
1048 |
if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY.equals(ejbType)) { |
1049 |
addConnectionFactoryReference(connectionFactoryName, beanNames, BEAN_TYPE.ENTITY); |
1050 |
addMsgDestReference(referenceName, destPrefix, destName, beanNames, BEAN_TYPE.ENTITY); |
1051 |
} |
1052 |
else |
1053 |
if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) { |
1054 |
addMsgDrvConnectionFactoryReference(connectionFactoryName, ejbName); |
1055 |
addMsgDrvMsgDestReference(referenceName, destPrefix, destName, ejbName); |
1056 |
} |
1057 |
|
1058 |
} |
1059 |
|
1060 |
|
907 |
/** |
1061 |
/** |
908 |
* Add a new message destination reference to the beans of the given type without it. |
1062 |
* Add a new message destination reference to the beans of the given type without it. |
909 |
* |
1063 |
* |
910 |
* @param msgDestRefName message destination reference name |
1064 |
* @param msgDestRefName message destination reference name |
|
|
1065 |
* @param destName message destination name |
1066 |
* @param detPrefix message destination prefix (queue/ ot topic/) |
911 |
* @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName |
1067 |
* @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName |
912 |
* @param beanType type of bean to add message destination reference to |
1068 |
* @param beanType type of bean to add message destination reference to |
913 |
*/ |
1069 |
*/ |
914 |
private void addMsgDestReference(final String msgDestRefName, final String destPrefix, |
1070 |
private void addMsgDestReference(final String msgDestRefName, final String destPrefix, final String destName, |
915 |
final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException |
1071 |
final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException |
916 |
{ |
1072 |
{ |
917 |
modifyJboss(new JbossModifier() { |
1073 |
modifyJboss(new JbossModifier() { |
918 |
public void modify(Jboss modifiedJboss) { |
1074 |
public void modify(Jboss modifiedJboss) { |
919 |
JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix); |
1075 |
JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix, destName); |
920 |
} |
1076 |
} |
921 |
}); |
1077 |
}); |
922 |
} |
1078 |
} |
Lines 925-939
Link Here
|
925 |
* Add a new message destination reference to the message driven beans without it. |
1081 |
* Add a new message destination reference to the message driven beans without it. |
926 |
* |
1082 |
* |
927 |
* @param msgDestRefName message destination reference name |
1083 |
* @param msgDestRefName message destination reference name |
928 |
* @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName |
1084 |
* @param destName message destination name |
929 |
* @param beanType type of bean to add message destination reference to |
1085 |
* @param destPrefix message destination prefix (queue/ ot topic/) |
|
|
1086 |
* @param mdbName the MDB (ejb-name value) which might need to add |
1087 |
* message destination reference specified by msgDestRefName |
930 |
*/ |
1088 |
*/ |
931 |
private void addMsgDrvMsgDestReference(final String msgDestRefName, final String destPrefix, |
1089 |
private void addMsgDrvMsgDestReference(final String msgDestRefName, final String destPrefix, |
932 |
final Map beans) throws ConfigurationException |
1090 |
final String destName, final String mdbName) throws ConfigurationException |
933 |
{ |
1091 |
{ |
934 |
modifyJboss(new JbossModifier() { |
1092 |
modifyJboss(new JbossModifier() { |
935 |
public void modify(Jboss modifiedJboss) { |
1093 |
public void modify(Jboss modifiedJboss) { |
936 |
JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, beans, destPrefix); |
1094 |
JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, mdbName, destPrefix, destName); |
937 |
} |
1095 |
} |
938 |
}); |
1096 |
}); |
939 |
} |
1097 |
} |