" */
paramString = (String)param;
if (paramString.length() < 3) {
throw new JDOUserException(
msg.msg("EXC_ObjectIdentityStringConstructionTooShort") + //NOI18N
msg.msg("EXC_ObjectIdentityStringConstructionUsage", //NOI18N
paramString));
}
int indexOfDelimiter = paramString.indexOf(STRING_DELIMITER);
if (indexOfDelimiter < 0) {
throw new JDOUserException(
msg.msg("EXC_ObjectIdentityStringConstructionNoDelimiter") + //NOI18N
msg.msg("EXC_ObjectIdentityStringConstructionUsage", //NOI18N
paramString));
}
keyString = paramString.substring(indexOfDelimiter+1);
className = paramString.substring(0, indexOfDelimiter);
keyAsObject = helper.construct(className, keyString);
} else {
keyAsObject = param;
}
hashCode = hashClassName() ^ keyAsObject.hashCode();
}
/** Constructor only for Externalizable.
*/
public ObjectIdentity () {
}
/** Return the key.
* @return the key
*/
public Object getKey () {
return keyAsObject;
}
/** Return the String form of the object id. The class of the
* object id is written as the first part of the result so that
* the class can be reconstructed later. Then the toString
* of the key instance is appended. During construction,
* this process is reversed. The class is extracted from
* the first part of the String, and the String constructor
* of the key is used to construct the key itself.
* @return the String form of the key
*/
@Override
public String toString () {
return keyAsObject.getClass().getName()
+ STRING_DELIMITER
+ keyAsObject.toString();
}
/** Determine if the other object represents the same object id.
* @param obj the other object
* @return true if both objects represent the same object id
*/
@Override
public boolean equals (Object obj) {
if (this == obj) {
return true;
} else if (!super.equals (obj)) {
return false;
} else {
ObjectIdentity other = (ObjectIdentity) obj;
return keyAsObject.equals(other.keyAsObject);
}
}
/** Provide the hash code for this instance. The hash code is the
* hash code of the contained key.
* @return the hash code
*/
@Override
public int hashCode() {
return keyAsObject.hashCode();
}
/** Determine the ordering of identity objects.
* @param o Other identity
* @return The relative ordering between the objects
* @since 2.2
*/
@SuppressWarnings("unchecked")
public int compareTo(Object o) {
if (o instanceof ObjectIdentity) {
ObjectIdentity other = (ObjectIdentity)o;
int result = super.compare(other);
if (result == 0) {
if (other.keyAsObject instanceof Comparable &&
keyAsObject instanceof Comparable) {
return ((Comparable)keyAsObject).compareTo(
(Comparable)other.keyAsObject);
}
else
{
throw new ClassCastException("The key class (" +
keyAsObject.getClass().getName() +
") does not implement Comparable");
}
} else {
return result;
}
}
else if (o == null) {
throw new ClassCastException("object is null");
}
throw new ClassCastException(this.getClass().getName() +
" != " + o.getClass().getName());
}
/** Write this object. Write the superclass first.
* @param out the output
*/
@Override
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal (out);
out.writeObject(keyAsObject);
}
/** Read this object. Read the superclass first.
* @param in the input
*/
@Override
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
super.readExternal (in);
keyAsObject = in.readObject();
}
}
api/src/java/javax/jdo/identity/package.html 100664 2005 12500110371 21342 0 ustar mbouschen staff 0 0
Identity package
This package contains the JDO specification identity interfaces and classes.
api/src/java/javax/jdo/identity/ShortIdentity.java 100664 10076 12500110371 22564 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* ShortIdentity.java
*
*/
package javax.jdo.identity;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/** This class is for identity with a single short field.
* @version 2.0
*/
public class ShortIdentity
extends SingleFieldIdentity
{
private short key;
private void construct(short key) {
this.key = key;
hashCode = hashClassName() ^ key;
}
/** Constructor with class and key.
* @param pcClass the class
* @param key the key
*/
public ShortIdentity (Class pcClass, short key) {
super(pcClass);
construct(key);
}
/** Constructor with class and key.
* @param pcClass the class
* @param key the key
*/
public ShortIdentity (Class pcClass, Short key) {
super(pcClass);
setKeyAsObject(key);
construct(key.shortValue());
}
/** Constructor with class and key.
* @param pcClass the class
* @param str the key
*/
public ShortIdentity (Class pcClass, String str) {
super(pcClass);
assertKeyNotNull(str);
construct(Short.parseShort (str));
}
/** Constructor only for Externalizable.
*/
public ShortIdentity () {
}
/** Return the key.
* @return the key
*/
public short getKey () {
return key;
}
/** Return the String form of the key.
* @return the String form of the key
*/
public String toString () {
return Short.toString(key);
}
/** Determine if the other object represents the same object id.
* @param obj the other object
* @return true if both objects represent the same object id
*/
public boolean equals (Object obj) {
if (this == obj) {
return true;
} else if (!super.equals (obj)) {
return false;
} else {
ShortIdentity other = (ShortIdentity) obj;
return key == other.key;
}
}
/** Determine the ordering of identity objects.
* @param o Other identity
* @return The relative ordering between the objects
* @since 2.2
*/
public int compareTo(Object o) {
if (o instanceof ShortIdentity) {
ShortIdentity other = (ShortIdentity)o;
int result = super.compare(other);
if (result == 0) {
return (key - other.key);
} else {
return result;
}
}
else if (o == null) {
throw new ClassCastException("object is null");
}
throw new ClassCastException(this.getClass().getName() + " != " + o.getClass().getName());
}
/** Create the key as an Object.
* @return the key as an Object
* @since 2.0
*/
protected Object createKeyAsObject() {
return new Short(key);
}
/** Write this object. Write the superclass first.
* @param out the output
*/
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal (out);
out.writeShort(key);
}
/** Read this object. Read the superclass first.
* @param in the input
*/
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
super.readExternal (in);
key = in.readShort();
}
}
api/src/java/javax/jdo/identity/SingleFieldIdentity.java 100664 13611 12500110371 23650 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* SingleFieldIdentity.java
*
*/
package javax.jdo.identity;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import javax.jdo.JDOFatalInternalException;
import javax.jdo.JDONullIdentityException;
import javax.jdo.spi.I18NHelper;
/** This class is the abstract base class for all single field identity
* classes. A common case of application identity uses exactly one
* persistent field in the class to represent identity. In this case,
* the application can use a standard JDO class instead of creating
* a new user-defined class for the purpose.
* @version 2.0
*/
public abstract class SingleFieldIdentity
implements Externalizable, Comparable {
/** The Internationalization message helper.
*/
protected static I18NHelper msg = I18NHelper.getInstance ("javax.jdo.Bundle"); //NOI18N
/** The class of the target object.
*/
transient private Class targetClass;
/** The name of the class of the target object.
*/
private String targetClassName;
/** The hashCode.
*/
protected int hashCode;
/** The key as an Object.
*/
protected Object keyAsObject;
/** Constructor with target class.
* @param pcClass the class of the target
* @since 2.0
*/
protected SingleFieldIdentity(Class pcClass) {
if (pcClass == null)
throw new NullPointerException();
targetClass = pcClass;
targetClassName = pcClass.getName();
}
/** Constructor only for Externalizable.
* @since 2.0
*/
public SingleFieldIdentity () {
}
/** Set the given key as the key for this instance.
* Compute the hash code for the instance.
* @since 2.0
*/
protected void setKeyAsObject(Object key) {
assertKeyNotNull(key);
keyAsObject = key;
}
/** Assert that the key is not null. Throw a JDONullIdentityException
* if the given key is null.
* @since 2.0
*/
protected void assertKeyNotNull(Object key) {
if (key == null) {
throw new JDONullIdentityException(
msg.msg("EXC_SingleFieldIdentityNullParameter")); //NOI18N
}
}
/** Return the target class.
* @return the target class.
* @since 2.0
*/
public Class getTargetClass() {
return targetClass;
}
/** Return the target class name.
* @return the target class name.
* @since 2.0
*/
public String getTargetClassName() {
return targetClassName;
}
/** Return the key as an Object. The method is synchronized to avoid
* race conditions in multi-threaded environments.
* @return the key as an Object.
* @since 2.0
*/
public synchronized Object getKeyAsObject() {
if (keyAsObject == null) {
keyAsObject = createKeyAsObject();
}
return keyAsObject;
}
/** Create the key as an Object.
* @return the key as an Object;
* @since 2.0
*/
protected Object createKeyAsObject() {
throw new JDOFatalInternalException
(msg.msg("EXC_CreateKeyAsObjectMustNotBeCalled"));
}
/** Check the class and class name and object type. If restored
* from serialization, class will be null so compare class name.
* @param obj the other object
* @return true if the class or class name is the same
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj == null || this.getClass() != obj.getClass()) {
return false;
} else {
SingleFieldIdentity other = (SingleFieldIdentity) obj;
if (targetClass != null && targetClass == other.targetClass)
return true;
return targetClassName.equals (other.targetClassName);
}
}
/** Return the hash code of the class name.
* @return the hash code of the class name
* @since 2.0
*/
protected int hashClassName() {
return targetClassName.hashCode();
}
/** Return the cached hash code.
* @return the cached hash code.
*/
public int hashCode() {
return hashCode;
}
/** Write to the output stream.
* @param out the stream
*/
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(targetClassName);
out.writeInt(hashCode);
}
/** Read from the input stream.
* Creates a new instance with the target class name set
*/
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
targetClass = null;
targetClassName = (String)in.readObject();
hashCode = in.readInt();
}
/** Determine the ordering of identity objects. Only the class name
* is compared. This method is only used by subclasses.
* @param o Other identity
* @return The relative ordering between the objects
* @since 2.2
*/
protected int compare(SingleFieldIdentity o) {
return targetClassName.compareTo(o.targetClassName);
}
}
api/src/java/javax/jdo/identity/StringIdentity.java 100664 6773 12500110371 22724 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* StringIdentity.java
*
*/
package javax.jdo.identity;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/** This class is for identity with a single String field.
* @version 2.0
*/
public class StringIdentity extends SingleFieldIdentity {
/** The key is stored in the superclass field keyAsObject.
*/
/** Constructor with class and key.
* @param pcClass the class
* @param key the key
*/
public StringIdentity (Class pcClass, String key) {
super (pcClass);
setKeyAsObject(key);
hashCode = hashClassName() ^ key.hashCode();
}
/** Constructor only for Externalizable.
*/
public StringIdentity () {
}
/** Return the key.
* @return the key
*/
public String getKey () {
return (String)keyAsObject;
}
/** Return the String form of the key.
* @return the String form of the key
*/
public String toString () {
return (String)keyAsObject;
}
/** Determine if the other object represents the same object id.
* @param obj the other object
* @return true if both objects represent the same object id
*/
public boolean equals (Object obj) {
if (this == obj) {
return true;
} else if (!super.equals (obj)) {
return false;
} else {
StringIdentity other = (StringIdentity) obj;
return keyAsObject.equals(other.keyAsObject);
}
}
/** Determine the ordering of identity objects.
* @param o Other identity
* @return The relative ordering between the objects
* @since 2.2
*/
public int compareTo(Object o) {
if (o instanceof StringIdentity) {
StringIdentity other = (StringIdentity)o;
int result = super.compare(other);
if (result == 0) {
return ((String)keyAsObject).compareTo((String)other.keyAsObject);
} else {
return result;
}
}
else if (o == null) {
throw new ClassCastException("object is null");
}
throw new ClassCastException(this.getClass().getName() + " != " + o.getClass().getName());
}
/** Write this object. Write the superclass first.
* @param out the output
*/
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal (out);
out.writeObject(keyAsObject);
}
/** Read this object. Read the superclass first.
* @param in the input
*/
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
super.readExternal (in);
keyAsObject = (String)in.readObject();
}
}
api/src/java/javax/jdo/InstanceCallbacks.java 100664 6147 12500110371 21452 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* InstanceCallbacks.java
*
*/
package javax.jdo;
/** A PersistenceCapable
class that provides callback methods for life
* cycle events implements this interface.
*
* For JDO 2.0, InstanceCallbacks
has been refactored to extend
* four other interfaces, without changing any of the methods or semantics.
* This allows fine-grained control over callbacks, for
* example to allow a class to implement the load callback without
* implementing any of the other callbacks. For backward compatibility
* with JDO 1.0, the InstanceCallbacks
interface is preserved.
*
*
Classes which include non-persistent fields whose values depend
* on the values of persistent fields require callbacks on specific
* JDO instance life cycle events in order to correctly populate the
* values in these fields.
*
*
The callbacks might also be used if the persistent instances
* need to be put into the runtime infrastructure of the application.
* For example, a persistent instance might notify other instances
* on changes to state. The persistent instance might be in a list of
* managed instances. When the persistent instance is made hollow,
* it can no longer generate change events, and the persistent
* instance should be removed from the list of managed instances.
*
*
To implement this, the application programmer would implement
* jdoPostLoad
to put itself into the list of managed
* instances, and implement jdoPreClear
to remove itself from
* the list. With JDO 1.0, the domain class would be declared to implement
* InstanceCallbacks
. With JDO 2.0, the domain class
* would be declared to implement
* javax.jdo.listener.LoadCallback
and
* javax.jdo.listener.ClearCallback
.
*
*
Note that JDO does not manage the state of non-persistent
* fields, and when a JDO instance transitions to hollow, JDO clears
* the persistent fields. It is the programmer's responsibility to
* clear non-persistent fields so that garbage collection of
* referred instances can occur.
*
* @since 1.0
* @version 2.0
*/
public interface InstanceCallbacks
extends javax.jdo.listener.ClearCallback,
javax.jdo.listener.DeleteCallback,
javax.jdo.listener.LoadCallback,
javax.jdo.listener.StoreCallback {
}
api/src/java/javax/jdo/JDOCanRetryException.java 100664 6027 12500110371 22046 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* JDOCanRetryException.java
*
*/
package javax.jdo;
/** This is the base class for exceptions that can be retried.
*
* @version 1.0
*/
public class JDOCanRetryException extends JDOException {
/**
* Constructs a new JDOCanRetryException
without a detail message.
*/
public JDOCanRetryException() {
}
/**
* Constructs a new JDOCanRetryException
with the specified detail message.
* @param msg the detail message.
*/
public JDOCanRetryException(String msg) {
super(msg);
}
/**
* Constructs a new JDOCanRetryException
with the specified detail
* message and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
*/
public JDOCanRetryException(String msg, Throwable[] nested) {
super(msg, nested);
}
/**
* Constructs a new JDOCanRetryException
with the specified detail
* message and nested Throwables.
* @param msg the detail message.
* @param nested the nested Throwable
.
*/
public JDOCanRetryException(String msg, Throwable nested) {
super(msg, nested);
}
/** Constructs a new JDOCanRetryException
with the specified detail message
* and failed object.
* @param msg the detail message.
* @param failed the failed object.
*/
public JDOCanRetryException(String msg, Object failed) {
super(msg, failed);
}
/** Constructs a new JDOCanRetryException
with the specified detail message,
* nested Throwable
s, and failed object.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
* @param failed the failed object.
*/
public JDOCanRetryException(String msg, Throwable[] nested, Object failed) {
super(msg, nested, failed);
}
/** Constructs a new JDOCanRetryException
with the specified detail message,
* nested Throwable
s, and failed object.
* @param msg the detail message.
* @param nested the nested Throwable
.
* @param failed the failed object.
*/
public JDOCanRetryException(String msg, Throwable nested, Object failed) {
super(msg, nested, failed);
}
}
api/src/java/javax/jdo/JDODataStoreException.java 100664 6060 12500110371 22202 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* JDODataStoreException.java
*
*/
package javax.jdo;
/** This class represents data store exceptions that can be retried.
*
* @version 1.0
*/
public class JDODataStoreException extends JDOCanRetryException {
/**
* Constructs a new JDODataStoreException
without a detail message.
*/
public JDODataStoreException() {
}
/**
* Constructs a new JDODataStoreException
with the specified detail message.
* @param msg the detail message.
*/
public JDODataStoreException(String msg) {
super(msg);
}
/**
* Constructs a new JDODataStoreException
with the specified
* detail message and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
*/
public JDODataStoreException(String msg, Throwable[] nested) {
super(msg, nested);
}
/**
* Constructs a new JDODataStoreException
with the specified
* detail message and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable
.
*/
public JDODataStoreException(String msg, Throwable nested) {
super(msg, nested);
}
/** Constructs a new JDODataStoreException
with the specified detail message
* and failed object.
* @param msg the detail message.
* @param failed the failed object.
*/
public JDODataStoreException(String msg, Object failed) {
super(msg, failed);
}
/** Constructs a new JDODataStoreException
with the specified detail message,
* nested Throwable
s, and failed object.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
* @param failed the failed object.
*/
public JDODataStoreException(String msg, Throwable[] nested, Object failed) {
super(msg, nested, failed);
}
/** Constructs a new JDODataStoreException
with the specified detail message,
* nested Throwable
s, and failed object.
* @param msg the detail message.
* @param nested the nested Throwable
.
* @param failed the failed object.
*/
public JDODataStoreException(String msg, Throwable nested, Object failed) {
super(msg, nested, failed);
}
}
api/src/java/javax/jdo/JDODetachedFieldAccessException.java 100664 5014 12500110371 24101 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* JDODetachedFieldAccessException.java
*
*/
package javax.jdo;
/** This class represents exceptions caused by access of an unloaded field while
* the instance is detached.
*
* @version 2.0
* @since 2.0
*/
public class JDODetachedFieldAccessException extends JDOUserException {
/**
* Constructs a new JDODetachedFieldAccessException
without a
* detail message.
* @since 2.0
*/
public JDODetachedFieldAccessException() {
}
/**
* Constructs a new JDODetachedFieldAccessException
with the
* specified detail message.
* @param msg the detail message.
* @since 2.0
*/
public JDODetachedFieldAccessException(String msg) {
super(msg);
}
/** Constructs a new JDODetachedFieldAccessException
* with the specified detail message
* and failed object.
* @param msg the detail message.
* @param failed the failed object.
*/
public JDODetachedFieldAccessException(String msg, Object failed) {
super(msg, failed);
}
/**
* Constructs a new JDODetachedFieldAccessException
with the
* specified detail message and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
* @since 2.0
*/
public JDODetachedFieldAccessException(String msg, Throwable[] nested) {
super(msg, nested);
}
/**
* Constructs a new JDODetachedFieldAccessException
with the
* specified detail message and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable
.
* @since 2.0
*/
public JDODetachedFieldAccessException(String msg, Throwable nested) {
super(msg, nested);
}
}
api/src/java/javax/jdo/JDOEnhanceException.java 100664 3770 12500110371 21662 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.jdo;
/**
* Exception thrown when an error occurs during enhancement.
* @since 3.0
*/
public class JDOEnhanceException extends JDOException
{
/**
* Constructs a new JDOEnhanceException
without a
* detail message.
*/
public JDOEnhanceException()
{
}
/**
* Constructs a new JDOEnhanceException
with the
* specified detail message.
* @param msg the detail message.
*/
public JDOEnhanceException(String msg)
{
super(msg);
}
/**
* Constructs a new JDOEnhanceException
with the
* specified detail message and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
*/
public JDOEnhanceException(String msg, Throwable[] nested)
{
super(msg, nested);
}
/**
* Constructs a new JDOEnhanceException
with the
* specified detail message and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable
.
*/
public JDOEnhanceException(String msg, Throwable nested)
{
super(msg, nested);
}
}
api/src/java/javax/jdo/JDOEnhancer.java 100664 13052 12500110371 20177 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.jdo;
import java.lang.instrument.ClassFileTransformer;
import java.util.Properties;
import javax.jdo.metadata.JDOMetadata;
/**
* Interface for a JDO Enhancer.
* @since 3.0
*/
public interface JDOEnhancer extends ClassFileTransformer
{
/**
* Return non-configurable properties of this JDOEnhancer.
* Properties with keys "VendorName" and "VersionNumber" are required.
* Other keys are optional.
* @return the non-configurable properties of this JDOEnhancer.
*/
Properties getProperties();
/**
* Whether to provide verbose output
* @param flag Verbose?
* @return The enhancer
*/
JDOEnhancer setVerbose(boolean flag);
/**
* Mutator to set the location where enhanced classes are written.
* Mutator to set the location where enhanced classes are written.
* If this method is not called, classes will be enhanced in place,
* overwriting the existing classes. If overwriting classes in a jar file,
* the existing files in the jar file will be written unchanged except
* for the enhanced classes. The directory name can be absolute or relative.
* @param dirName Name of the directory
* @return The enhancer
*/
JDOEnhancer setOutputDirectory(String dirName);
/**
* Mutator to set the class loader to use for loading classes.
* @param loader ClassLoader to use
* @return The enhancer
*/
JDOEnhancer setClassLoader(ClassLoader loader);
/**
* Add a persistence-unit to the items to be enhanced.
* @param persistenceUnit Name of the persistence unit
* @return The enhancer
*/
JDOEnhancer addPersistenceUnit(String persistenceUnit);
/**
* Add an in-memory class to the items to be enhanced.
* The class name should be of the form "mydomain.MyClass".
* @param className Name of the class
* @param bytes The bytes of the class
* @return The enhancer
*/
JDOEnhancer addClass(String className, byte[] bytes);
/**
* Add class(es) to the items to be enhanced.
* The class names can be absolute file names, relative file names, or
* names of CLASSPATH resources.
* @param classNames Names of the classes
* @return The enhancer
*/
JDOEnhancer addClasses(String... classNames);
/**
* Add metadata file(s) to the items to be enhanced.
* The metadata file names can be absolute file names, relative file names, or
* names of CLASSPATH resources. They should be JDO XML metadata files.
* @param metadataFiles Names of the files
* @return The enhancer
*/
JDOEnhancer addFiles(String... metadataFiles);
/**
* Add a jar file to the items to be enhanced.
* The jar file name can be absolute, or relative or a CLASSPATH resource.
* @param jarFileName Name of the jar file
* @return The enhancer
*/
JDOEnhancer addJar(String jarFileName);
/**
* Method to enhance the items specified using addJar, addFiles, addClasses, addClass,
* addPersistenceUnit.
* @return Number of classes enhanced
* @throws JDOEnhanceException if an error occurs during enhancement. If multiple
* errors occur then the nested exceptions provides this detail.
*/
int enhance();
/**
* Method to validate the items specified using addJar, addFiles, addClasses, addClass,
* addPersistenceUnit.
* @return Number of classes validated
* @throws JDOEnhanceException if an error occurs during validation. If multiple
* errors occur then the nested exceptions provides this detail.
*/
int validate();
/**
* Method to retrieve the (enhanced) bytes of the specified class.
* Only applies to the classes enhanced in the most recent enhance() call.
* If no enhance has yet been performed will throw a JDOEnhanceException.
* If the specified class hasn't been enhanced then will throw a JDOEnhanceException.
* @param className Name of the class (of the form "mydomain.MyClass")
* @return Enhanced bytes
*/
byte[] getEnhancedBytes(String className);
/**
* Method to register metadata with the enhancement process managed by this
* JDOEnhancer
.
* Metadata can be created using the method {@link #newMetadata}.
* If there is already metadata registered for a class contained in this metadata
* object then a JDOUserException will be thrown.
* @param metadata The Metadata to register.
* @since 3.0
*/
void registerMetadata(JDOMetadata metadata);
/**
* Method to return a new metadata object that can be subsequently modified
* and registered with the enhancement process using the method {@link #registerMetadata}.
* @return The metadata
* @since 3.0
*/
JDOMetadata newMetadata();
}
api/src/java/javax/jdo/JDOException.java 100664 24712 12500110371 20417 0 ustar mbouschen staff 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* JDOException.java
*
*/
package javax.jdo;
import javax.jdo.spi.I18NHelper;
/** This is the root of all JDO Exceptions. It contains an optional detail
* message, an optional nested Throwable
array and an optional failed object.
* @author Craig Russell
* @version 1.0.2
*/
public class JDOException extends java.lang.RuntimeException {
/** This exception was generated because of an exception in the runtime library.
* @serial the nested Throwable
array
*/
Throwable[] nested;
/** This exception may be the result of incorrect parameters supplied
* to an API. This is the object from which the user can determine
* the cause of the problem.
* @serial the failed Object
*/
Object failed;
/** The Internationalization message helper.
*/
private static I18NHelper msg = I18NHelper.getInstance ("javax.jdo.Bundle"); //NOI18N
/** Flag indicating whether printStackTrace is being executed.
*/
private boolean inPrintStackTrace = false;
/**
* Constructs a new JDOException
without a detail message.
*/
public JDOException() {
}
/**
* Constructs a new JDOException
with the specified detail message.
* @param msg the detail message.
*/
public JDOException(String msg) {
super(msg);
}
/** Constructs a new JDOException
with the specified detail message
* and nested Throwable
s.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
*/
public JDOException(String msg, Throwable[] nested) {
super(msg);
this.nested = nested;
}
/** Constructs a new JDOException
with the specified detail message
* and nested Throwable
.
* @param msg the detail message.
* @param nested the nested Throwable
.
*/
public JDOException(String msg, Throwable nested) {
super(msg);
this.nested = new Throwable[] {nested};
}
/** Constructs a new JDOException
with the specified detail message
* and failed object.
* @param msg the detail message.
* @param failed the failed object.
*/
public JDOException(String msg, Object failed) {
super(msg);
this.failed = failed;
}
/** Constructs a new JDOException
with the specified detail message,
* nested Throwable
s, and failed object.
* @param msg the detail message.
* @param nested the nested Throwable[]
.
* @param failed the failed object.
*/
public JDOException(String msg, Throwable[] nested, Object failed) {
super(msg);
this.nested = nested;
this.failed = failed;
}
/** Constructs a new JDOException
with the specified detail message,
* nested Throwable
, and failed object.
* @param msg the detail message.
* @param nested the nested Throwable
.
* @param failed the failed object.
*/
public JDOException(String msg, Throwable nested, Object failed) {
super(msg);
this.nested = new Throwable[] {nested};
this.failed = failed;
}
/** The exception may include a failed object.
* @return the failed object.
*/
public Object getFailedObject() {
return failed;
}
/** The exception may have been caused by multiple exceptions in the runtime.
* If multiple objects caused the problem, each failed object will have
* its own Exception
.
* @return the nested Throwable array.
*/
public Throwable[] getNestedExceptions() {
return nested;
}
/** Often there is only one nested exception, and this method returns it.
* If there are more than one, then this method returns the first nested
* exception. If there is no nested exception, then null is returned.
* @return the first or only nested Throwable.
* @since 1.0.1
*/
public synchronized Throwable getCause() {
// super.printStackTrace calls getCause to handle the cause.
// Returning null prevents the superclass from handling the cause;
// instead the local implementation of printStackTrace should
// handle the cause. Otherwise, the cause is printed twice.
if (nested == null || nested.length == 0 || inPrintStackTrace) {
return null;
} else {
return nested[0];
}
}
/** JDK 1.4 includes a new chaining mechanism for Throwable, but since
* JDO has its own "legacy" chaining mechanism, the "standard" mechanism
* cannot be used. This method always throws a JDOFatalInternalException.
* @param cause ignored.
* @return never.
*/
public Throwable initCause(Throwable cause) {
throw new JDOFatalInternalException(msg.msg("ERR_CannotInitCause"));
}
/** The String
representation includes the name of the class,
* the descriptive comment (if any),
* the String
representation of the failed Object
(if any),
* and the String
representation of the nested Throwable
s (if any).
* @return the String
.
*/
public synchronized String toString() {
int len = nested==null?0:nested.length;
// calculate approximate size of the String to return
StringBuffer sb = new StringBuffer (10 + 100 * len);
sb.append (super.toString());
// include failed object information
if (failed != null) {
sb.append ("\n").append (msg.msg ("MSG_FailedObject"));
String failedToString = null;
try {
failedToString = failed.toString();
} catch (Exception ex) {
// include the information from the exception thrown by failed.toString
Object objectId = JDOHelper.getObjectId(failed);
if (objectId == null) {
failedToString = msg.msg("MSG_ExceptionGettingFailedToString", //NOI18N
exceptionToString(ex));
}
else {
// include the ObjectId information
String objectIdToString = null;
try {
objectIdToString = objectId.toString();
}
catch (Exception ex2) {
objectIdToString = exceptionToString(ex2);
}
failedToString = msg.msg("MSG_ExceptionGettingFailedToStringObjectId", //NOI18N
exceptionToString(ex), objectIdToString);
}
}
sb.append (failedToString);
}
// include nested Throwable information, but only if not called by
// printStackTrace; the stacktrace will include the cause anyway.
if (len > 0 && !inPrintStackTrace) {
sb.append ("\n").append (msg.msg ("MSG_NestedThrowables")).append ("\n");
Throwable exception = nested[0];
sb.append (exception==null?"null":exception.toString()); //NOI18N
for (int i=1; iJDOException
and its backtrace to the
* standard error output.
* Print nested Throwables' stack trace as well.
*/
public void printStackTrace() {
printStackTrace (System.err);
}
/**
* Prints this JDOException
and its backtrace to the
* specified print stream.
* Print nested Throwables' stack trace as well.
* @param s PrintStream
to use for output
*/
public synchronized void printStackTrace(java.io.PrintStream s) {
int len = nested==null?0:nested.length;
synchronized (s) {
inPrintStackTrace = true;
super.printStackTrace(s);
if (len > 0) {
s.println (msg.msg ("MSG_NestedThrowablesStackTrace"));
for (int i=0; iJDOException
and its backtrace to the specified
* print writer.
* Print nested Throwables' stack trace as well.
* @param s PrintWriter
to use for output
*/
public synchronized void printStackTrace(java.io.PrintWriter s) {
int len = nested==null?0:nested.length;
synchronized (s) {
inPrintStackTrace = true;
super.printStackTrace(s);
if (len > 0) {
s.println (msg.msg ("MSG_NestedThrowablesStackTrace"));
for (int i=0; i