Skip to content

Commit

Permalink
A couple more new exceptions and conversion of exception generation t…
Browse files Browse the repository at this point in the history
…o localized messages.
  • Loading branch information
drallen committed Nov 8, 2009
1 parent 9fa9129 commit de82252
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 11 deletions.
43 changes: 43 additions & 0 deletions impl/src/main/java/org/jboss/weld/InvalidObjectException.java
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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 org.jboss.weld;

import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import ch.qos.cal10n.IMessageConveyor;

/**
* An extended version of {@link java.io.InvalidObjectException} that supports
* localization.
*
* @author David Allen
*
*/
public class InvalidObjectException extends java.io.InvalidObjectException
{

private static final long serialVersionUID = 1L;

// Exception messages
private static final IMessageConveyor messageConveyer = loggerFactory().getMessageConveyor();

public <E extends Enum<?>> InvalidObjectException(E key, Object... args)
{
super(messageConveyer.getMessage(key, args));
}

}
38 changes: 38 additions & 0 deletions impl/src/main/java/org/jboss/weld/NullInstanceException.java
@@ -0,0 +1,38 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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 org.jboss.weld;

/**
* This exception occurs in cases where an object instance was expected, but
* the reference was null. A typical example is with a producer method that
* is not allowed to return null.
*
* @author David Allen
*
*/
public class NullInstanceException extends WeldException
{

private static final long serialVersionUID = 1L;

public <E extends Enum<?>> NullInstanceException(E key, Object... args)
{
super(key, args);
}

}
Expand Up @@ -3,6 +3,7 @@
import static org.jboss.weld.logging.Category.BEAN;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.BeanMessage.CALL_PROXIED_METHOD;
import static org.jboss.weld.logging.messages.BeanMessage.NULL_INSTANCE;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -11,6 +12,7 @@

import javassist.util.proxy.MethodHandler;

import org.jboss.weld.NullInstanceException;
import org.slf4j.cal10n.LocLogger;

public class CallableMethodHandler implements MethodHandler, Serializable
Expand All @@ -37,7 +39,7 @@ public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[]
Object instance = callable.call();
if (instance == null)
{
throw new NullPointerException("Unable to obtain instance. Bean: " + callable);
throw new NullInstanceException(NULL_INSTANCE, callable);
}
try
{
Expand Down
Expand Up @@ -16,9 +16,9 @@
*/
package org.jboss.weld.bean.builtin;

import static org.jboss.weld.logging.messages.BeanMessage.PROXY_REQUIRED;
import static org.jboss.weld.util.Reflections.EMPTY_ANNOTATIONS;

import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
Expand All @@ -35,6 +35,7 @@
import javax.enterprise.util.TypeLiteral;

import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.InvalidObjectException;
import org.jboss.weld.resolution.ResolvableWeldClass;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Names;
Expand Down Expand Up @@ -152,7 +153,7 @@ private Object writeReplace() throws ObjectStreamException

private void readObject(ObjectInputStream stream) throws InvalidObjectException
{
throw new InvalidObjectException("Proxy required");
throw new InvalidObjectException(PROXY_REQUIRED);
}

private static class SerializationProxy extends AbstractFacadeSerializationProxy
Expand Down
@@ -1,5 +1,8 @@
package org.jboss.weld.bean.builtin.ee;

import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.HashSet;
Expand Down Expand Up @@ -35,11 +38,11 @@ protected AbstractEEBean(Class<T> type, Callable<T> callable, BeanManagerImpl be
}
catch (InstantiationException e)
{
throw new DefinitionException("Could not instantiate client proxy for " + this, e);
throw new DefinitionException(PROXY_INSTANTIATION_FAILED, e, this);
}
catch (IllegalAccessException e)
{
throw new DefinitionException("Could not access bean correctly when creating client proxy for " + this, e);
throw new DefinitionException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
}
}

Expand Down
Expand Up @@ -16,22 +16,27 @@
*/
package org.jboss.weld.bean.builtin.ee;

import static org.jboss.weld.logging.messages.BeanMessage.BEAN_NOT_EE_RESOURCE_PRODUCER;
import static org.jboss.weld.logging.messages.BeanMessage.INVALID_RESOURCE_PRODUCER_FIELD;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;

import java.io.Serializable;

import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;

import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.ForbiddenStateException;
import org.jboss.weld.Container;
import org.jboss.weld.ForbiddenStateException;
import org.jboss.weld.WeldException;
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.ProducerField;
import org.jboss.weld.bean.builtin.CallableMethodHandler;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.logging.messages.BeanMessage;
import org.jboss.weld.persistence.PersistenceApiAbstraction;
import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.util.Proxies;
Expand Down Expand Up @@ -75,7 +80,7 @@ public T call() throws Exception
}
else
{
throw new IllegalStateException("Bean is not an EE resource producer field. Bean: " + contextual);
throw new ForbiddenStateException(BEAN_NOT_EE_RESOURCE_PRODUCER, contextual);
}
}
return instance;
Expand Down Expand Up @@ -120,11 +125,11 @@ protected EEResourceProducerField(WeldField<T, X> field, AbstractClassBean<X> de
}
catch (InstantiationException e)
{
throw new RuntimeException("Error creating proxy for resource producer field. Field: " + this, e);
throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
}
catch (IllegalAccessException e)
{
throw new RuntimeException("Error creating proxy for resource field. Field: " + this, e);
throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
}
}

Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.jboss.weld.bean.proxy;

import static org.jboss.weld.logging.messages.BeanMessage.BEAN_ID_CREATION_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;

import java.io.Serializable;
Expand Down Expand Up @@ -85,7 +86,7 @@ private static <T> T createClientProxy(Bean<T> bean, BeanManagerImpl manager, St
}
catch (IllegalAccessException e)
{
throw new WeldException(BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, bean);
throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, bean);
}
}

Expand Down
Expand Up @@ -60,6 +60,9 @@ public enum BeanMessage
@MessageId("000039") TYPED_CLASS_NOT_IN_HIERARCHY,
@MessageId("000040") MULTIPLE_SCOPES_FOUND_FROM_STEREOTYPES,
@MessageId("000041") NAME_NOT_ALLOWED_ON_SPECIALIZATION,
@MessageId("000042") NON_CONTAINER_DECORATOR
@MessageId("000042") NON_CONTAINER_DECORATOR,
@MessageId("000043") BEAN_NOT_EE_RESOURCE_PRODUCER,
@MessageId("000044") NULL_INSTANCE,
@MessageId("000045") PROXY_REQUIRED

}
Expand Up @@ -22,6 +22,8 @@ DELEGATE_INJECTION_POINT_NOT_FOUND=Delegate injection point not found on decorat
ANNOTATION_NOT_BINDING=The annotation {0} is not a binding for {1}
DUPLICATE_BINDING=The annotation {0} is already present in the bindings list for {1}
TYPE_PARAMETER_MUST_BE_CONCRETE=Type parameter must be a concrete type\: {0}
BEAN_NOT_EE_RESOURCE_PRODUCER=The following bean is not an EE resource producer\: {0}
NULL_INSTANCE=Unable to obtain instance from {0}
VALIDATION_SERVICE_NOT_AVAILABLE=ValidationServices are not available
INVALID_RESOURCE_PRODUCER_FIELD=Tried to create an EEResourceProducerField, but no @Resource, @PersistenceContext, @PersistenceUnit, @WebServiceRef or @EJB is present {0}
SECURITY_SERVICES_NOT_AVAILABLE=SecurityServices not available
Expand All @@ -41,3 +43,4 @@ MULTIPLE_SCOPES_FOUND_FROM_STEREOTYPES=All stereotypes must specify the same sco
NON_CONTAINER_DECORATOR=Cannot operate on non container provided decorator {0}
NAME_NOT_ALLOWED_ON_SPECIALIZATION=Cannot put name on specializing and specialized class {0}
INTERCEPTION_TYPE_NOT_LIFECYCLE=InterceptionType must be lifecycle, but it is {0}
PROXY_REQUIRED=Proxy required

0 comments on commit de82252

Please sign in to comment.