Update of
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-ejb/src/main/java/org/xdoclet/plugin/ejb
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6319/plugin-ejb/src/main/java/org/xdoclet/plugin/ejb
Modified Files:
EjbUtils.java
Added Files:
EjbVersion.java EjbRuntime.java EjbConfig.java EjbIds.java
Log Message:
alpha commit
--- NEW FILE: EjbVersion.java ---
/*
* Copyright (c) 2005
* XDoclet Team
* All rights reserved.
*/
package org.xdoclet.plugin.ejb;
import java.util.HashMap;
import java.util.Map;
/**
* @author Diogo Quintela
*/
public class EjbVersion {
public static final String EJB_1_1 = "1.1";
public static final String EJB_2_0 = "2.0";
public static final String EJB_2_1 = "2.1";
private static Map versionMap = new HashMap();
private String publicId;
private String systemId;
private String ns;
private String xsdLocation;
private boolean isDtd;
private String xsiNs;
private double version;
static {
versionMap.put(EJB_1_1,
new EjbVersion(1.1, "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 1.1//EN",
"http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd"));
versionMap.put(EJB_2_0,
new EjbVersion(2.0, "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN",
"http://java.sun.com/dtd/ejb-jar_2_0.dtd"));
versionMap.put(EJB_2_1,
new EjbVersion(2.1, "http://java.sun.com/xml/ns/j2ee",
"http://www.w3.org/2001/XMLSchema-instance",
"http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"));
}
/**
* Usable for DTDs
*/
private EjbVersion(double version, String publicId, String systemId) {
this.version = version;
this.publicId = publicId;
this.systemId = systemId;
this.isDtd = true;
}
/**
* Usable for XSDs
*/
private EjbVersion(double version, String ns, String xsiNs, String
xsdLocation) {
this.version = version;
this.ns = ns;
this.xsiNs = xsiNs;
this.xsdLocation = xsdLocation;
this.isDtd = false;
}
public static EjbVersion get(String version) {
return (EjbVersion) versionMap.get(version);
}
public boolean greaterOrEquals(String ver) {
return greaterOrEquals(Double.parseDouble(ver));
}
public boolean greaterOrEquals(double ver) {
return ver <= getVersion();
}
public boolean equals(String ver) {
return equals(Double.parseDouble(ver));
}
public boolean equals(double ver) {
return ver == getVersion();
}
/**
* Utility method to get the online reference for DTD/XSD
*/
private static String getLocationUrl(String version) {
EjbVersion ejbVer = get(version);
if (ejbVer == null) {
throw new IllegalStateException();
}
return ejbVer.isDtd() ? ejbVer.getSystemId() : ejbVer.getXsdLocation();
}
public String getPublicId() {
return this.publicId;
}
public String getSchemaLocation() {
if (this.ns == null || this.xsdLocation == null) {
return null;
}
return this.ns + " " + this.xsdLocation;
}
public String getSystemId() {
return this.systemId;
}
public String getNs() {
return this.ns;
}
public String getXsdLocation() {
return this.xsdLocation;
}
public boolean isDtd() {
return this.isDtd;
}
public String getXsiNs() {
return this.xsiNs;
}
public double getVersion() {
return this.version;
}
public static Map fillEntityResolverMap(Map dtds) {
Class clz = EjbVersion.class;
dtds.put(getLocationUrl(EJB_1_1),
clz.getResource("dtd/ejb-jar_1_1.dtd"));
dtds.put(getLocationUrl(EJB_2_0),
clz.getResource("dtd/ejb-jar_2_0.dtd"));
dtds.put(getLocationUrl(EJB_2_1),
clz.getResource("dtd/ejb-jar_2_1.xsd"));
// Referenced by http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd
dtds.put("http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd",
clz.getResource("dtd/j2ee_1_4.xsd"));
// Referenced by http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd
dtds.put("http://www.w3.org/2001/xml.xsd",
clz.getResource("dtd/xml.xsd"));
// Referenced by http://www.w3.org/2001/xml.xsd
dtds.put("http://www.w3.org/2001/XMLSchema.dtd",
clz.getResource("dtd/XMLSchema.dtd"));
// Referenced by http://www.w3.org/2001/XMLSchema.dtd
dtds.put("http://www.w3.org/2001/datatypes.dtd",
clz.getResource("dtd/datatypes.dtd"));
// Referenced by http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd
dtds.put("http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd",
clz.getResource("dtd/j2ee_web_services_client_1_1.xsd"));
return dtds;
}
}
--- NEW FILE: EjbRuntime.java ---
/*
* Copyright (c) 2005
* XDoclet Team
* All rights reserved.
*/
package org.xdoclet.plugin.ejb;
import org.generama.QDoxCapableMetadataProvider;
import org.xdoclet.plugin.ejb.descriptor.EjbJarXmlPlugin;
import org.xdoclet.plugin.ejb.entity.PrimaryKeyClassPlugin;
import org.xdoclet.plugin.ejb.interfaces.LocalHomeInterfacePlugin;
import org.xdoclet.plugin.ejb.interfaces.LocalInterfacePlugin;
import org.xdoclet.plugin.ejb.interfaces.RemoteHomeInterfacePlugin;
import org.xdoclet.plugin.ejb.interfaces.RemoteInterfacePlugin;
/**
* A singleton class to manage the needed relationship between ejb generating
plugins,
* without constructing then and using the plugin constructor.
* This enables the user not set the usage of a plugin he doesn't want
*
* @author Diogo Quintela
*
* TODO: Is this the better pattern to resolve the problem ? Should we support
any subclassing ?
*/
public class EjbRuntime {
protected static EjbRuntime instance;
protected final EjbConfig config;
protected QDoxCapableMetadataProvider metadataProvider;
protected EjbJarXmlPlugin ejbJarXmlPlugin;
protected PrimaryKeyClassPlugin primaryKeyClassPlugin;
protected LocalHomeInterfacePlugin localHomeInterfacePlugin;
protected LocalInterfacePlugin localInterfacePlugin;
protected RemoteHomeInterfacePlugin remoteHomeInterfacePlugin;
protected RemoteInterfacePlugin remoteInterfacePlugin;
protected EjbRuntime(EjbConfig config, QDoxCapableMetadataProvider
metadataProvider) {
// No public instantiation
this.config = config;
this.metadataProvider = metadataProvider;
}
public static synchronized void init(EjbConfig config,
QDoxCapableMetadataProvider metadataProvider) {
if (config == null || metadataProvider == null) {
throw new Error("NullPointerException");
}
if (instance == null) {
instance = new EjbRuntime(config, metadataProvider);
}
// else: We have already been initialized ignore values
}
public static LocalInterfacePlugin getLocalInterfacePlugin() throws
ClassNotFoundException {
checkInit();
return instance._getLocalInterfacePlugin();
}
public static RemoteHomeInterfacePlugin getRemoteHomeInterfacePlugin()
throws ClassNotFoundException {
checkInit();
return instance._getRemoteHomeInterfacePlugin();
}
public static RemoteInterfacePlugin getRemoteInterfacePlugin() throws
ClassNotFoundException {
checkInit();
return instance._getRemoteInterfacePlugin();
}
protected synchronized LocalInterfacePlugin _getLocalInterfacePlugin()
throws ClassNotFoundException {
if (this.localInterfacePlugin == null) {
this.localInterfacePlugin = new LocalInterfacePlugin(null,
metadataProvider, null, config);
}
return this.localInterfacePlugin;
}
protected synchronized RemoteHomeInterfacePlugin
_getRemoteHomeInterfacePlugin() throws ClassNotFoundException {
if (this.remoteHomeInterfacePlugin == null) {
this.remoteHomeInterfacePlugin = new
RemoteHomeInterfacePlugin(null, metadataProvider, null, config);
}
return this.remoteHomeInterfacePlugin;
}
protected synchronized RemoteInterfacePlugin _getRemoteInterfacePlugin()
throws ClassNotFoundException {
if (this.remoteInterfacePlugin == null) {
this.remoteInterfacePlugin = new RemoteInterfacePlugin(null,
metadataProvider, null, config);
}
return this.remoteInterfacePlugin;
}
public static EjbJarXmlPlugin getEjbJarXmlPlugin() throws
ClassNotFoundException {
checkInit();
return instance._getEjbJarXmlPlugin();
}
protected synchronized EjbJarXmlPlugin _getEjbJarXmlPlugin() throws
ClassNotFoundException {
if (this.ejbJarXmlPlugin == null) {
this.ejbJarXmlPlugin = new EjbJarXmlPlugin(null, metadataProvider,
null, config);
}
return this.ejbJarXmlPlugin;
}
public static PrimaryKeyClassPlugin getPrimaryKeyClassPlugin() throws
ClassNotFoundException {
checkInit();
return instance._getPrimaryKeyClassPlugin();
}
protected synchronized PrimaryKeyClassPlugin _getPrimaryKeyClassPlugin()
throws ClassNotFoundException {
if (this.primaryKeyClassPlugin == null) {
this.primaryKeyClassPlugin = new PrimaryKeyClassPlugin(null,
metadataProvider, null, config);
}
return this.primaryKeyClassPlugin;
}
public static LocalHomeInterfacePlugin getLocalHomeInterfacePlugin() throws
ClassNotFoundException {
checkInit();
return instance._getLocalHomeInterfacePlugin();
}
protected synchronized LocalHomeInterfacePlugin
_getLocalHomeInterfacePlugin()
throws ClassNotFoundException {
if (this.localHomeInterfacePlugin == null) {
this.localHomeInterfacePlugin = new LocalHomeInterfacePlugin(null,
metadataProvider, null, config);
}
return this.localHomeInterfacePlugin;
}
public static void setPlugin(PrimaryKeyClassPlugin plugin) {
if (plugin == null) {
throw new Error("NullPointerException");
}
checkInit();
instance._setPlugin(plugin);
}
public static void setPlugin(EjbJarXmlPlugin plugin) {
if (plugin == null) {
throw new Error("NullPointerException");
}
checkInit();
instance._setPlugin(plugin);
}
public static void setPlugin(LocalHomeInterfacePlugin plugin) {
if (plugin == null) {
throw new Error("NullPointerException");
}
checkInit();
instance._setPlugin(plugin);
}
public static void setPlugin(LocalInterfacePlugin plugin) {
if (plugin == null) {
throw new Error("NullPointerException");
}
checkInit();
instance._setPlugin(plugin);
}
public static void setPlugin(RemoteHomeInterfacePlugin plugin) {
if (plugin == null) {
throw new Error("NullPointerException");
}
checkInit();
instance._setPlugin(plugin);
}
public static void setPlugin(RemoteInterfacePlugin plugin) {
if (plugin == null) {
throw new Error("NullPointerException");
}
checkInit();
instance._setPlugin(plugin);
}
protected synchronized void _setPlugin(RemoteInterfacePlugin plugin) {
this.remoteInterfacePlugin = plugin;
}
protected synchronized void _setPlugin(RemoteHomeInterfacePlugin plugin) {
this.remoteHomeInterfacePlugin = plugin;
}
protected synchronized void _setPlugin(LocalInterfacePlugin plugin) {
this.localInterfacePlugin = plugin;
}
protected synchronized void _setPlugin(LocalHomeInterfacePlugin plugin) {
this.localHomeInterfacePlugin = plugin;
}
protected synchronized void _setPlugin(EjbJarXmlPlugin plugin) {
this.ejbJarXmlPlugin = plugin;
}
protected synchronized void _setPlugin(PrimaryKeyClassPlugin plugin) {
this.primaryKeyClassPlugin = plugin;
}
protected synchronized static void checkInit() {
if (instance == null) {
throw new Error("EjbRuntime wasn't initialized");
}
}
public static EjbConfig getConfig() {
checkInit();
return instance._getConfig();
}
protected EjbConfig _getConfig() {
return this.config;
}
}
Index: EjbUtils.java
===================================================================
RCS file:
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-ejb/src/main/java/org/xdoclet/plugin/ejb/EjbUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** EjbUtils.java 2 Jul 2005 20:44:53 -0000 1.5
--- EjbUtils.java 26 Aug 2005 17:52:30 -0000 1.6
***************
*** 1,4 ****
/*
! * Copyright (c) 2003
* XDoclet Team
* All rights reserved.
--- 1,4 ----
/*
! * Copyright (c) 2005
* XDoclet Team
* All rights reserved.
***************
[...1567 lines suppressed...]
+ retLst.add(new MethodPermission(REMOTE_HOME_INTERFACE, roles,
method));
+ }
+
+ if (hasFlag(permType, LOCAL)) {
+ retLst.add(new MethodPermission(LOCAL_INTERFACE, roles,
method));
+ }
+
+ if (hasFlag(permType, LOCAL_HOME)) {
+ retLst.add(new MethodPermission(LOCAL_HOME_INTERFACE, roles,
method));
+ }
+
+ if (hasFlag(permType, SERVICE_END_POINT)) {
+ retLst.add(new MethodPermission(SERVICE_END_POINT_INTERFACE,
roles, method));
+ }
+
+ return retLst;
+ }
+ }
}
\ No newline at end of file
--- NEW FILE: EjbConfig.java ---
/*
* Copyright (c) 2005
* XDoclet Team
* All rights reserved.
*/
package org.xdoclet.plugin.ejb;
import java.util.regex.Pattern;
/**
* Configuration object common to EJB plugins
*
* @author Diogo Quintela
* @version $Revision: 1.1 $
*/
public class EjbConfig {
private EjbVersion version = EjbVersion.get(EjbVersion.EJB_2_1);
private String ejbreplaceregex = "Bean|EJB|Ejb";
/**
* Sets the version for generated config file
* @generama.property required="false" default="2.0" allowed-values="1.1,
2.0, 2.1"
* TODO: Remember to set 2.0 as default :)
*/
public void setVersion(String version) {
EjbVersion ejbVersion = EjbVersion.get(version);
if (ejbVersion == null) {
throw new IllegalArgumentException("Incorrect ejb-jar version : " +
version);
}
this.version = ejbVersion;
}
public EjbVersion getVersion() {
return this.version;
}
public String getEjbReplaceRegex() {
return this.ejbreplaceregex;
}
/**
* Sets the EJB Replace Regex for EJB Plugins.
* Needs to be a acceptable regular expression for [EMAIL PROTECTED]
java.lang.String#replaceAll(java.lang.String, java.lang.String)}
*
* @generama.property required="false" default="Bean|EJB|Ejb"
*/
public void setEjbreplaceregex(String ejbreplaceregex) {
if (ejbreplaceregex == null) {
throw new NullPointerException();
}
Pattern.compile(ejbreplaceregex);
this.ejbreplaceregex = ejbreplaceregex;
}
}
--- NEW FILE: EjbIds.java ---
/*
* Copyright (c) 2005
* XDoclet Team
* All rights reserved.
*/
package org.xdoclet.plugin.ejb;
import java.util.HashMap;
import java.util.Map;
/**
* Singleton for ID generation
* @author Diogo Quintela
*
* TODO: After all we aren't going to need to remember id's that we've returned.
* Maybe EjbRuntime can't also be used
*/
public class EjbIds {
private static EjbIds instance = new EjbIds();
private Map idManagers = new HashMap();
private EjbIds() {
// Empty
}
public static EjbIds get() {
return instance;
}
private synchronized IdManager getManager(String prefix) {
IdManager manager = (IdManager) idManagers.get(prefix);
if (manager == null) {
manager = new IdManager(prefix);
idManagers.put(prefix, manager);
}
return manager;
}
public String prefixedId(String prefix, Object object, String defId) {
IdManager manager = getManager(prefix);
return manager.getId(object, defId);
}
public String prefixedId(String prefix, Object object) {
return prefixedId(prefix, object, null);
}
private final class IdManager {
private int count = 0;
private Map objectIds = new HashMap();
private String prefix;
public IdManager(String prefix) {
this.prefix = prefix;
}
private String idFor(String defId) {
String id = defId;
if (id == null) {
id = String.valueOf(++count);
}
return id;
}
public synchronized String getId(Object object, String defId) {
String id = null;
if (object != null) {
id = (String) objectIds.get(object);
}
if (id == null) {
id = prefix + "_" + idFor(defId);
id = id.replace('-', '_');
id = id.replace('/', '_');
if (object != null) {
objectIds.put(object, id);
}
}
return id;
}
}
}
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
xdoclet-plugins-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xdoclet-plugins-commits