You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/02/13 19:21:20 UTC
cvs commit: db-ojb/src/connector/main/org/apache/ojb/jboss ODMGFactory.java ODMGFactoryMBean.java PBFactory.java PBFactoryMBean.java
arminw 2003/02/13 10:21:20
Added: src/connector/main/org/apache/ojb/jboss ODMGFactory.java
ODMGFactoryMBean.java PBFactory.java
PBFactoryMBean.java
Log:
move jboss based sources to
separate dir
Revision Changes Path
1.1 db-ojb/src/connector/main/org/apache/ojb/jboss/ODMGFactory.java
Index: ODMGFactory.java
===================================================================
package org.apache.ojb.jboss;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache ObjectRelationalBridge" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.ojb.odmg.ODMGJ2EEFactory;
import org.apache.ojb.odmg.OJBJ2EE_2;
import org.jboss.system.ServiceMBeanSupport;
import org.odmg.Implementation;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import java.io.Serializable;
public class ODMGFactory extends ServiceMBeanSupport
implements ODMGJ2EEFactory, Serializable, ODMGFactoryMBean
{
private static final String JAVA_NAMESPACE = "java:/";
private String jndiName;
private String repository;
private String user;
private String password;
public ODMGFactory()
{
System.out.println("ODMGFactory called");
}
protected void startService() throws Exception
{
try
{
bind(new InitialContext(), JAVA_NAMESPACE + jndiName, this);
}
catch (Exception e)
{
System.out.println("Binding ODMG to JNDI failed");
e.printStackTrace();
throw e;
}
System.out.println("** OJB-ODMG MBean integration");
System.out.println("** ODMGFactory: " + this.getClass().getName() + " / " + this.getServiceName().toString());
System.out.println("** Use ODMGFactory via lookup:");
System.out.println("** ODMGFactory factory = (ODMGFactory) ctx.lookup(" + JAVA_NAMESPACE + jndiName + ")");
System.out.println("** Implementation odmg = factory.getInstance();");
}
public void stopService()
{
try
{
(new InitialContext()).unbind(JAVA_NAMESPACE + jndiName);
}
catch (NamingException namingexception)
{
namingexception.printStackTrace();
}
}
public Implementation getInstance()
{
return OJBJ2EE_2.getInstance();
}
public void setJndiName(String jndiName)
{
this.jndiName = jndiName;
}
public String getJndiName()
{
return jndiName;
}
private void bind(Context ctx, String name, Object val) throws NamingException
{
Name n;
for (n = ctx.getNameParser("").parse(name); n.size() > 1; n = n.getSuffix(1))
{
String ctxName = n.get(0);
try
{
ctx = (Context) ctx.lookup(ctxName);
}
catch (NameNotFoundException namenotfoundexception)
{
ctx = ctx.createSubcontext(ctxName);
}
}
ctx.bind(n.get(0), val);
}
}
1.1 db-ojb/src/connector/main/org/apache/ojb/jboss/ODMGFactoryMBean.java
Index: ODMGFactoryMBean.java
===================================================================
package org.apache.ojb.jboss;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache ObjectRelationalBridge" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.jboss.system.ServiceMBean;
public interface ODMGFactoryMBean extends ServiceMBean
{
public void setJndiName(String s);
public String getJndiName();
}
1.1 db-ojb/src/connector/main/org/apache/ojb/jboss/PBFactory.java
Index: PBFactory.java
===================================================================
package org.apache.ojb.jboss;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache ObjectRelationalBridge" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.jboss.system.ServiceMBeanSupport;
import org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF;
import org.apache.ojb.broker.ta.PersistenceBrokerFactoryFactory;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameNotFoundException;
import java.io.Serializable;
/**
* mbean for the PersistenceBrokerFactory
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
*/
public class PBFactory extends ServiceMBeanSupport implements PBFactoryMBean, Serializable
{
private String _jndiName;
private static final String JAVA_NAMESPACE = "java:/";
public PersistenceBrokerFactoryIF getInstance()
{
return PersistenceBrokerFactoryFactory.instance();
}
public String getName()
{
return "PBAPI-Implementation";
}
protected void startService()
throws Exception
{
try
{
bind(new InitialContext(), JAVA_NAMESPACE + _jndiName, this);
}
catch (Throwable e)
{
e.printStackTrace();
}
getLog().info("PBFactory: "+this.getClass().getName()+" / "+this.getServiceName().toString());
getLog().info("Lookup PBFactory via '"+JAVA_NAMESPACE+_jndiName+"'");
}
public void stopService()
{
try
{
(new InitialContext()).unbind(JAVA_NAMESPACE + _jndiName);
}
catch (NamingException namingexception)
{
namingexception.printStackTrace();
}
}
public void setJndiName(String jndiName)
{
_jndiName = jndiName;
}
public String getJndiName()
{
return _jndiName;
}
private void bind(Context ctx, String name, Object val)
throws NamingException
{
Name n;
for (n = ctx.getNameParser("").parse(name); n.size() > 1; n = n.getSuffix(1))
{
String ctxName = n.get(0);
try
{
ctx = (Context) ctx.lookup(ctxName);
}
catch (NameNotFoundException namenotfoundexception)
{
ctx = ctx.createSubcontext(ctxName);
}
}
ctx.bind(n.get(0), val);
}
}
1.1 db-ojb/src/connector/main/org/apache/ojb/jboss/PBFactoryMBean.java
Index: PBFactoryMBean.java
===================================================================
package org.apache.ojb.jboss;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache ObjectRelationalBridge" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.jboss.system.ServiceMBean;
/**
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
*/
public interface PBFactoryMBean extends ServiceMBean, org.apache.ojb.broker.ta.PBFactoryIF
{
public void setJndiName(String jndiName);
public String getJndiName();
}