@Override
public <DV extends DataObject> DataContainerCodecContext<DV, ?> streamChild(Class<DV> childClass)
throws IllegalArgumentException {
+ /* FIXME: This is still not solved for RPCs
+ * TODO: Probably performance wise RPC, Data and Notification loading cache
+ * should be merge for performance resons. Needs microbenchmark to
+ * determine which is faster (keeping them separate or in same cache).
+ */
+ if (Notification.class.isAssignableFrom(childClass)) {
+ return (DataContainerCodecContext<DV, ?>) getNotification((Class<? extends Notification>)childClass);
+ }
return (DataContainerCodecContext<DV, ?>) childrenByClass.getUnchecked(childClass);
}
-/**
-
- *
- * March 2013
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.sal.binding.model.api.type.builder;
* The methods as {@link #addAnnotation(String, String)} and
* {@link #setComment(String)} can be used as optional because not all methods
* MUST contain annotation or comment definitions.
- *
- *
+ *
+ *
* @see MethodSignature
*/
public interface MethodSignatureBuilder extends TypeMemberBuilder<MethodSignatureBuilder> {
* the flag <code>isAbstract == true</code> The instantiated Method
* Signature MUST have return value for {@link MethodSignature#isAbstract()}
* also equals to <code>true</code>.
- *
+ *
* @param isAbstract
* is abstract flag
*/
/**
* Adds Parameter into the List of method parameters. Neither the Name or
* Type of parameter can be <code>null</code>.
- *
+ *
* <br>
* In case that any of parameters are defined as <code>null</code> the
* method SHOULD throw an {@link IllegalArgumentException}
- *
+ *
* @param type
* Parameter Type
* @param name
* <code>class</code> or <code>interface</code> definition. In case that
* defining Type will be passed as <code>null</code> reference the method
* SHOULD thrown {@link IllegalArgumentException}.
- *
+ *
* @param definingType
* Defining Type of Method Signature
* @return <code>new</code> <i>immutable</i> instance of Method Signature.
-/**
-
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
- * March 2013
- *
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.sal.binding.model.api.type.builder;
\ No newline at end of file
-/**
-
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
- * March 2013
- *
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.sal.binding.model.api.type.provider;
\ No newline at end of file
*/
package org.opendaylight.yangtools.concepts;
-public interface ClassBasedPropertyBuilder<P,T extends ClassBasedPropertyBuilder<P,T>> extends Builder<P> {
-
+public interface ClassBasedPropertyBuilder<P, T extends ClassBasedPropertyBuilder<P, T>> extends Builder<P> {
/**
* Sets a value of property uniquely identified by its
* class.
- *
+ *
* @param type Type of property to set
- * @param value Value of property
+ * @param value Value of property
* @return Builder instance
*/
<V> T set(Class<V> type, V value);
-
+
/**
* Gets a value of property based on its type.
- *
+ *
* @param type Type of property to get
* @return Builder instance
*/
return new CompositeObjectRegistrationBuilder<>(instance);
}
- public static final class CompositeObjectRegistrationBuilder<T> implements //
- Builder<CompositeObjectRegistration<T>> {
+ public static final class CompositeObjectRegistrationBuilder<T> implements Builder<CompositeObjectRegistration<T>> {
private final T instance;
private final Set<Registration> registrations;
*/
package org.opendaylight.yangtools.concepts;
-public interface Deserializer<P,I> {
-
+/**
+ * The concept of a serializer, which produces an object from some input.
+ *
+ * @param <P> Product type
+ * @param <I> Input type
+ */
+public interface Deserializer<P, I> {
+ /**
+ * Produce an object base on input.
+ *
+ * @param input Input object
+ * @return Product derived from input
+ */
P deserialize(I input);
}
*/
package org.opendaylight.yangtools.concepts;
-public interface InvertibleTransformator<P, I> extends Transformator<P, I>{
+public interface InvertibleTransformator<P, I> extends Transformator<P, I> {
I fromProduct(P product);
/**
* Mutable object - object may change it's state during lifecycle.
- *
+ *
* This interface is mutually exclusive with {@link Immutable} and other
* {@link MutationBehaviour}s.
- *
+ *
* @author Tony Tkacik
*
*/
-public interface Mutable extends MutationBehaviour<Mutable>{
-
+public interface Mutable extends MutationBehaviour<Mutable> {
+
}
* @param <P> Product type
*/
public interface ProductAwareBuilder<P> extends Builder<P> {
- /**
- * Return the hash code of the product. This has to be equivalent
- * of calling {@link #build()}.{@link Object#hashCode()}.
- *
- * @return the hash code of the product.
- */
- int productHashCode();
+ /**
+ * Return the hash code of the product. This has to be equivalent
+ * of calling {@link #build()}.{@link Object#hashCode()}.
+ *
+ * @return the hash code of the product.
+ */
+ int productHashCode();
- /**
- * Check whether an instance of the product that would be created
- * by the builder is equal to an existing instance. This has to
- * be equivalent of calling {@link #build()}.{@link Object#equals(Object)}.
- *
- * @param product Product instance
- * @return Return true if the product is equal to the would-be
- * product of the builder.
- */
- boolean productEquals(Object product);
+ /**
+ * Check whether an instance of the product that would be created
+ * by the builder is equal to an existing instance. This has to
+ * be equivalent of calling {@link #build()}.{@link Object#equals(Object)}.
+ *
+ * @param product Product instance
+ * @return Return true if the product is equal to the would-be
+ * product of the builder.
+ */
+ boolean productEquals(Object product);
}
*/
package org.mockito.configuration;
+import java.util.List;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.internal.invocation.InvocationsFinder;
import org.mockito.internal.verification.api.VerificationData;
import org.mockito.invocation.Invocation;
import org.mockito.verification.VerificationMode;
-import java.util.List;
-
/**
* Verifier that extracts arguments from actual invocation. Useful when deeper validation of arguments is needed.
- *
*/
public class ArgumentsExtractorVerifier implements VerificationMode {
- private Object[] arguments;
+ private Object[] arguments;
- @Override
- public void verify(VerificationData data) {
- InvocationsFinder finder = new InvocationsFinder();
- List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
- if (actualInvocations.size() != 1) {
- throw new MockitoException("This verifier can only be used with 1 invocation, got " + actualInvocations.size());
- }
- Invocation invocation = actualInvocations.get(0);
- arguments = invocation.getArguments();
- invocation.markVerified();
+ @Override
+ public void verify(final VerificationData data) {
+ InvocationsFinder finder = new InvocationsFinder();
+ List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
+ if (actualInvocations.size() != 1) {
+ throw new MockitoException("This verifier can only be used with 1 invocation, got " + actualInvocations.size());
+ }
+ Invocation invocation = actualInvocations.get(0);
+ arguments = invocation.getArguments();
+ invocation.markVerified();
- }
- public Object[] getArguments(){
- return arguments;
- }
- }
+ }
+ public Object[] getArguments() {
+ return arguments;
+ }
+}
* Configuration customization for Mockito. Change default answer to {@link ThrowsUnstubbedMethodException}.
*/
public class MockitoConfiguration extends DefaultMockitoConfiguration {
-
- @Override
- public Answer<Object> getDefaultAnswer() {
- return new ThrowsUnstubbedMethodException();
- }
+ @Override
+ public Answer<Object> getDefaultAnswer() {
+ return new ThrowsUnstubbedMethodException();
+ }
}
package org.mockito.configuration;
import java.io.Serializable;
-
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
* Answer that throws {@link UnstubbedMethodException}.
*/
public class ThrowsUnstubbedMethodException implements Answer<Object>, Serializable {
- private static final long serialVersionUID = 1L;
-
- public ThrowsUnstubbedMethodException() {
- }
+ private static final long serialVersionUID = 1L;
@Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- Throwable t = new UnstubbedMethodException(invocation.toString() + " was not stubbed");
- throw t;
+ public Object answer(final InvocationOnMock invocation) throws UnstubbedMethodException {
+ throw new UnstubbedMethodException(invocation.toString() + " was not stubbed");
}
}
*/
package org.mockito.configuration;
-
/**
* Exception to be thrown on unstubbed method call.
*/
public class UnstubbedMethodException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
- private static final long serialVersionUID = 1L;
-
- public UnstubbedMethodException(String message) {
- super(message);
- }
-
+ public UnstubbedMethodException(final String message) {
+ super(message);
+ }
}
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.concepts.ProductAwareBuilder;
* a cache in the instantiation path, one can expend some memory on
* indexes and spend some CPU cycles on walking the index to potentially
* end up with a reused object.
- *
+ *
* Note that the cached objects should really be semantically {@link Immutable}.
* This interface does not enforce that interface contract simply because
* there are third-party objects which fulfill this contract.
*/
public interface ObjectCache {
- /**
- * Get a reference for an object which is equal to specified object.
- * The cache is free return either a cached instance, or retain the
- * object and return it back.
- *
- * @param object Requested object, may be null
- * @return Reference to an object which is equal to the one passed in.
- * If @object was @null, this method returns @null.
- */
- <T> T getReference(@Nullable T object);
+ /**
+ * Get a reference for an object which is equal to specified object.
+ * The cache is free return either a cached instance, or retain the
+ * object and return it back.
+ *
+ * @param <T> object type
+ * @param object Requested object, may be null
+ * @return Reference to an object which is equal to the one passed in.
+ * If @object was @null, this method returns @null.
+ */
+ <T> T getReference(@Nullable T object);
- /**
- * Get a reference to an object equal to the product of a builder.
- * The builder is expected to remain constant while this method
- * executes. Unlike {@link #getReference(Object)}, this method has
- * the potential of completely eliding the product instantiation.
- *
- * @param builder Builder instance, may not be null
- * @return Result of builder's toInstance() product, or an equal
- * object.
- */
- <B extends ProductAwareBuilder<P>, P> P getProduct(@Nonnull B builder);
+ /**
+ * Get a reference to an object equal to the product of a builder.
+ * The builder is expected to remain constant while this method
+ * executes. Unlike {@link #getReference(Object)}, this method has
+ * the potential of completely eliding the product instantiation.
+ *
+ * @param <P> produced object type
+ * @param <B> builder type
+ * @param builder Builder instance, may not be null
+ * @return Result of builder's toInstance() product, or an equal
+ * object.
+ */
+ <B extends ProductAwareBuilder<P>, P> P getProduct(@Nonnull B builder);
}
* it at compile-time, but it is not packaged and thus not present at run-time.
*/
public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder {
- private StaticObjectCacheBinder() {
- super(null);
- }
+ private StaticObjectCacheBinder() {
+ super(null);
+ }
- public static StaticObjectCacheBinder getInstance() {
- throw new IllegalStateException("This class should have been replaced");
- }
+ public static StaticObjectCacheBinder getInstance() {
+ throw new IllegalStateException("This class should have been replaced");
+ }
}
protected abstract static class SoftKey<T> extends FinalizableSoftReference<T> {
private final int hashCode;
- public SoftKey(final T referent, final FinalizableReferenceQueue q) {
- super(Preconditions.checkNotNull(referent), q);
+ public SoftKey(final T referent, final FinalizableReferenceQueue queue) {
+ super(Preconditions.checkNotNull(referent), queue);
hashCode = referent.hashCode();
}
*/
package org.opendaylight.yangtools.objcache.spi;
-import javax.annotation.Nonnull;
-
import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
public abstract class AbstractObjectCacheBinder implements ObjectCacheFactoryBinder {
- private final IObjectCacheFactory factory;
+ private final IObjectCacheFactory factory;
- protected AbstractObjectCacheBinder(@Nonnull final IObjectCacheFactory factory) {
- this.factory = Preconditions.checkNotNull(factory);
- }
+ protected AbstractObjectCacheBinder(@Nonnull final IObjectCacheFactory factory) {
+ this.factory = Preconditions.checkNotNull(factory);
+ }
- @Override
- public final IObjectCacheFactory getProductCacheFactory() {
- return factory;
- }
+ @Override
+ public final IObjectCacheFactory getProductCacheFactory() {
+ return factory;
+ }
}
package org.opendaylight.yangtools.objcache.spi;
import javax.annotation.Nonnull;
-
import org.opendaylight.yangtools.objcache.ObjectCache;
public interface IObjectCacheFactory {
- ObjectCache getObjectCache(@Nonnull Class<?> objClass);
+ ObjectCache getObjectCache(@Nonnull Class<?> objClass);
}
* does not do any caching, so it only returns the request object.
*/
public final class NoopObjectCache implements ObjectCache {
- private static final NoopObjectCache INSTANCE = new NoopObjectCache();
+ private static final NoopObjectCache INSTANCE = new NoopObjectCache();
- private NoopObjectCache() {
+ private NoopObjectCache() {
- }
+ }
- /**
- * Get the cache instance. Since the cache does not have any state,
- * this method always returns a singleton instance.
- *
- * @return Cache instance.
- */
- public static NoopObjectCache getInstance() {
- return INSTANCE;
- }
+ /**
+ * Get the cache instance. Since the cache does not have any state,
+ * this method always returns a singleton instance.
+ *
+ * @return Cache instance.
+ */
+ public static NoopObjectCache getInstance() {
+ return INSTANCE;
+ }
- @Override
- public <T> T getReference(final T object) {
- return object;
- }
+ @Override
+ public <T> T getReference(final T object) {
+ return object;
+ }
- @Override
- public <B extends ProductAwareBuilder<P>, P> P getProduct(final B builder) {
- return builder.build();
- }
+ @Override
+ public <B extends ProductAwareBuilder<P>, P> P getProduct(final B builder) {
+ return builder.build();
+ }
}
* Interface binding an implementation into ObjectCacheFactory.
*/
public interface ObjectCacheFactoryBinder {
- /**
- * Get the implementation-specific cache factory.
- *
- * @return Implementation-specific factory.
- */
- IObjectCacheFactory getProductCacheFactory();
+ /**
+ * Get the implementation-specific cache factory.
+ *
+ * @return Implementation-specific factory.
+ */
+ IObjectCacheFactory getProductCacheFactory();
}
*/
package org.opendaylight.yangtools.objcache.guava;
+import com.google.common.base.FinalizableReferenceQueue;
import org.opendaylight.yangtools.objcache.ObjectCache;
import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
-import com.google.common.base.FinalizableReferenceQueue;
-
public final class GuavaObjectCacheFactory implements AutoCloseable, IObjectCacheFactory {
private static final GuavaObjectCacheFactory INSTANCE = new GuavaObjectCacheFactory();
private final FinalizableReferenceQueue queue = new FinalizableReferenceQueue();
@Override
public void close() {
- queue.close();
+ queue.close();
}
+ /**
+ * Return a factory instance.
+ *
+ * @return A factory instance.
+ */
public static GuavaObjectCacheFactory getInstance() {
return INSTANCE;
}
import org.opendaylight.yangtools.objcache.spi.AbstractObjectCacheBinder;
public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder {
- private static final StaticObjectCacheBinder INSTANCE = new StaticObjectCacheBinder();
+ private static final StaticObjectCacheBinder INSTANCE = new StaticObjectCacheBinder();
- private StaticObjectCacheBinder() {
- super(GuavaObjectCacheFactory.getInstance());
- }
+ private StaticObjectCacheBinder() {
+ super(GuavaObjectCacheFactory.getInstance());
+ }
- public static StaticObjectCacheBinder getInstance() {
- return INSTANCE;
- }
+ public static StaticObjectCacheBinder getInstance() {
+ return INSTANCE;
+ }
}
* @param collection Target collection
* @return An unmodifiable view of the collection
*/
- public static <T> Collection<T> create(final @Nonnull Collection<T> collection) {
- if (collection instanceof UnmodifiableCollection || collection instanceof ImmutableCollection ||
- Collections.EMPTY_LIST == collection || Collections.EMPTY_SET == collection ||
- UNMODIFIABLE_COLLECTION_CLASS.isInstance(collection) || SINGLETON_CLASSES.contains(collection.getClass())) {
+ public static <T> Collection<T> create(@Nonnull final Collection<T> collection) {
+ if (collection instanceof UnmodifiableCollection || collection instanceof ImmutableCollection
+ || Collections.EMPTY_LIST == collection || Collections.EMPTY_SET == collection
+ || UNMODIFIABLE_COLLECTION_CLASS.isInstance(collection)
+ || SINGLETON_CLASSES.contains(collection.getClass())) {
return collection;
}
package org.opendaylight.yangtools.util.concurrent;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.AbstractListeningExecutorService;
+import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
-
import javax.annotation.Nullable;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.AbstractListeningExecutorService;
-import com.google.common.util.concurrent.ListenableFuture;
-
/**
* An {@link com.google.common.util.concurrent.ListeningExecutorService} implementation that also allows for an {@link Executor} to be
* specified on construction that is used to execute {@link ListenableFuture} callback Runnables,
* @param listenableFutureExecutor the executor used to run listener callbacks asynchronously.
* If null, no executor is used.
*/
- public AsyncNotifyingListeningExecutorService( ExecutorService delegate,
- @Nullable Executor listenableFutureExecutor ) {
+ public AsyncNotifyingListeningExecutorService( final ExecutorService delegate,
+ @Nullable final Executor listenableFutureExecutor ) {
this.delegate = Preconditions.checkNotNull( delegate );
this.listenableFutureExecutor = listenableFutureExecutor;
}
*
* @param task the Callable to execute
*/
- private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( Callable<T> task ) {
+ private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( final Callable<T> task ) {
return AsyncNotifyingListenableFutureTask.create( task, listenableFutureExecutor );
}
*
* @param task the Runnable to execute
*/
- private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( Runnable task, T result ) {
+ private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( final Runnable task, final T result ) {
return AsyncNotifyingListenableFutureTask.create( task, result, listenableFutureExecutor );
}
}
@Override
- public boolean awaitTermination( long timeout, TimeUnit unit ) throws InterruptedException {
+ public boolean awaitTermination( final long timeout, final TimeUnit unit ) throws InterruptedException {
return delegate.awaitTermination( timeout, unit );
}
}
@Override
- public void execute( Runnable command ) {
+ public void execute( final Runnable command ) {
delegate.execute( command );
}
@Override
- public <T> ListenableFuture<T> submit( Callable<T> task ) {
+ public <T> ListenableFuture<T> submit( final Callable<T> task ) {
AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask( task );
delegate.execute( futureTask );
return futureTask;
}
@Override
- public ListenableFuture<?> submit( Runnable task ) {
+ public ListenableFuture<?> submit( final Runnable task ) {
AsyncNotifyingListenableFutureTask<Void> futureTask = newFutureTask( task, null );
delegate.execute( futureTask );
return futureTask;
}
@Override
- public <T> ListenableFuture<T> submit( Runnable task, T result ) {
+ public <T> ListenableFuture<T> submit( final Runnable task, final T result ) {
AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask( task, result );
delegate.execute( futureTask );
return futureTask;
}
- protected ToStringHelper addToStringAttributes( ToStringHelper toStringHelper ) {
+ protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) {
return toStringHelper;
}
@Override
- public final String toString(){
+ public final String toString() {
return addToStringAttributes( MoreObjects.toStringHelper( this )
.add( "delegate", delegate ) ).toString();
}
*/
package org.opendaylight.yangtools.util.concurrent;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
/**
* A ThreadPoolExecutor with a specified bounded queue capacity that favors reusing previously
* @param threadPrefix
* the name prefix for threads created by this executor.
*/
- public CachedThreadPoolExecutor( int maximumPoolSize, int maximumQueueSize, String threadPrefix ) {
+ public CachedThreadPoolExecutor( final int maximumPoolSize, final int maximumQueueSize, final String threadPrefix ) {
// We're using a custom SynchronousQueue that has a backing bounded LinkedBlockingQueue.
// We don't specify any core threads (first parameter) so, when a task is submitted,
// the base class will always try to offer to the queue. If there is an existing waiting
}
@Override
- public void setRejectedExecutionHandler( RejectedExecutionHandler handler ) {
+ public void setRejectedExecutionHandler( final RejectedExecutionHandler handler ) {
Preconditions.checkNotNull( handler );
rejectedTaskHandler.setDelegateRejectedExecutionHandler( handler );
}
@Override
- public RejectedExecutionHandler getRejectedExecutionHandler(){
+ public RejectedExecutionHandler getRejectedExecutionHandler() {
return rejectedTaskHandler.getDelegateRejectedExecutionHandler();
}
@Override
- public BlockingQueue<Runnable> getQueue(){
+ public BlockingQueue<Runnable> getQueue() {
return executorQueue.getBackingQueue();
}
return ((TrackingLinkedBlockingQueue<?>)executorQueue.getBackingQueue()).getLargestQueueSize();
}
- protected ToStringHelper addToStringAttributes( ToStringHelper toStringHelper ) {
+ protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) {
return toStringHelper;
}
private final LinkedBlockingQueue<Runnable> backingQueue;
- ExecutorQueue( int maxBackingQueueSize ) {
+ ExecutorQueue( final int maxBackingQueueSize ) {
backingQueue = new TrackingLinkedBlockingQueue<>( maxBackingQueueSize );
}
}
@Override
- public Runnable poll( long timeout, TimeUnit unit ) throws InterruptedException {
+ public Runnable poll( final long timeout, final TimeUnit unit ) throws InterruptedException {
long totalWaitTime = unit.toMillis( timeout );
long waitTime = Math.min( totalWaitTime, POLL_WAIT_TIME_IN_MS );
Runnable task = null;
// periods, one thread will eventually wake up and get the task from the backingQueue
// and execute it, although slightly delayed.
- while( task == null ) {
+ while (task == null) {
// First try to get a task from the backing queue.
task = backingQueue.poll();
- if( task == null ) {
+ if (task == null) {
// No task in backing - call the base class to wait for one to be offered.
task = super.poll( waitTime, TimeUnit.MILLISECONDS );
private final LinkedBlockingQueue<Runnable> backingQueue;
private volatile RejectedExecutionHandler delegateRejectedExecutionHandler;
- RejectedTaskHandler( LinkedBlockingQueue<Runnable> backingQueue,
- RejectedExecutionHandler delegateRejectedExecutionHandler ) {
+ RejectedTaskHandler( final LinkedBlockingQueue<Runnable> backingQueue,
+ final RejectedExecutionHandler delegateRejectedExecutionHandler ) {
this.backingQueue = backingQueue;
this.delegateRejectedExecutionHandler = delegateRejectedExecutionHandler;
}
void setDelegateRejectedExecutionHandler(
- RejectedExecutionHandler delegateRejectedExecutionHandler ) {
+ final RejectedExecutionHandler delegateRejectedExecutionHandler ) {
this.delegateRejectedExecutionHandler = delegateRejectedExecutionHandler;
}
}
@Override
- public void rejectedExecution( Runnable task, ThreadPoolExecutor executor ) {
- if( executor.isShutdown() ) {
+ public void rejectedExecution( final Runnable task, final ThreadPoolExecutor executor ) {
+ if (executor.isShutdown()) {
throw new RejectedExecutionException( "Executor has been shutdown." );
}
- if( !backingQueue.offer( task ) ) {
+ if (!backingQueue.offer(task)) {
delegateRejectedExecutionHandler.rejectedExecution( task, executor );
}
}
package org.opendaylight.yangtools.util.concurrent;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
/**
* A ThreadPoolExecutor with a specified bounded queue capacity that favors creating new threads
* @param threadPrefix
* the name prefix for threads created by this executor.
*/
- public FastThreadPoolExecutor( int maximumPoolSize, int maximumQueueSize, String threadPrefix ) {
+ public FastThreadPoolExecutor( final int maximumPoolSize, final int maximumQueueSize, final String threadPrefix ) {
this( maximumPoolSize, maximumQueueSize, DEFAULT_IDLE_TIMEOUT_IN_SEC, TimeUnit.SECONDS,
threadPrefix );
}
* @param threadPrefix
* the name prefix for threads created by this executor.
*/
- public FastThreadPoolExecutor( int maximumPoolSize, int maximumQueueSize, long keepAliveTime,
- TimeUnit unit, String threadPrefix ) {
+ public FastThreadPoolExecutor( final int maximumPoolSize, final int maximumQueueSize, final long keepAliveTime,
+ final TimeUnit unit, final String threadPrefix ) {
// We use all core threads (the first 2 parameters below equal) so, when a task is submitted,
// if the thread limit hasn't been reached, a new thread will be spawned to execute
// the task even if there is an existing idle thread in the pool. This is faster than
setThreadFactory( new ThreadFactoryBuilder().setDaemon( true )
.setNameFormat( threadPrefix + "-%d" ).build() );
- if( keepAliveTime > 0 ) {
+ if (keepAliveTime > 0) {
// Need to specifically configure core threads to timeout.
allowCoreThreadTimeOut( true );
}
return ((TrackingLinkedBlockingQueue<?>)getQueue()).getLargestQueueSize();
}
- protected ToStringHelper addToStringAttributes( ToStringHelper toStringHelper ) {
+ protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) {
return toStringHelper;
}
private final String listenerClassName;
private final int currentQueueSize;
- @ConstructorProperties({"listenerClassName","currentQueueSize"})
- public ListenerNotificationQueueStats( String listenerClassName, int currentQueueSize ) {
+ @ConstructorProperties({ "listenerClassName","currentQueueSize" })
+ public ListenerNotificationQueueStats( final String listenerClassName, final int currentQueueSize ) {
this.listenerClassName = listenerClassName;
this.currentQueueSize = currentQueueSize;
}
/**
* Returns the name of the listener class.
*/
- public String getListenerClassName(){
+ public String getListenerClassName() {
return listenerClassName;
}
/**
* Returns the current notification queue size.
*/
- public int getCurrentQueueSize(){
+ public int getCurrentQueueSize() {
return currentQueueSize;
}
}
package org.opendaylight.yangtools.yang.binding;
import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
-
import java.text.SimpleDateFormat;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
public static String getPropertyName(final String yangIdentifier) {
final String potential = toFirstLower(toCamelCase(yangIdentifier));
- if("class".equals(potential)) {
+ if ("class".equals(potential)) {
return "xmlClass";
}
return potential;
*/
package org.opendaylight.yangtools.yang.binding;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import org.opendaylight.yangtools.util.HashCodeBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
final class InstanceIdentifierBuilderImpl<T extends DataObject> implements InstanceIdentifier.InstanceIdentifierBuilder<T> {
private final ImmutableList.Builder<PathArgument> pathBuilder = ImmutableList.builder();
private final HashCodeBuilder<PathArgument> hashBuilder;
}
@SuppressWarnings("unchecked")
- <N extends DataObject & Identifiable<K> , K extends Identifier<N>> InstanceIdentifierBuilderImpl<N> addNode(final Class<N> listItem, final K listKey) {
+ <N extends DataObject & Identifiable<K>, K extends Identifier<N>> InstanceIdentifierBuilderImpl<N> addNode(final Class<N> listItem, final K listKey) {
arg = new IdentifiableItem<N, K>(listItem, listKey);
hashBuilder.addArgument(arg);
pathBuilder.add(arg);
/*
* @deprecated Use #build() instead.
*/
+ @Override
@Deprecated
public InstanceIdentifier<T> toInstance() {
return build();
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.yangtools.yang.binding.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
-
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
* Path, which is nested to parent, and should be readed.
* @return Value of object.
*/
- public static final <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData(P parent,
- InstanceIdentifier<P> parentPath, InstanceIdentifier<T> childPath) {
+ public static final <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData(final P parent,
+ final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath) {
checkArgument(parent != null, "Parent must not be null.");
checkArgument(parentPath != null, "Parent path must not be null");
checkArgument(childPath != null, "Child path must not be null");
}
@SuppressWarnings("rawtypes")
- private static Map<InstanceIdentifier, DataContainer> readData(Entry<InstanceIdentifier, DataContainer> entry,
- PathArgument pathArgument) {
+ private static Map<InstanceIdentifier, DataContainer> readData(final Entry<InstanceIdentifier, DataContainer> entry,
+ final PathArgument pathArgument) {
return readData(entry.getValue(), entry.getKey(), pathArgument);
}
- public static final <T extends DataObject> Optional<T> readData(DataObject source, Class<T> child) {
+ public static final <T extends DataObject> Optional<T> readData(final DataObject source, final Class<T> child) {
checkArgument(source != null, "Object should not be null.");
checkArgument(child != null, "Child type should not be null");
Class<? extends DataContainer> parentClass = source.getImplementedInterface();
}
@SuppressWarnings("rawtypes")
- private static final Map<InstanceIdentifier, DataContainer> readData(DataContainer parent,
- InstanceIdentifier parentPath, PathArgument child) {
+ private static final Map<InstanceIdentifier, DataContainer> readData(final DataContainer parent,
+ final InstanceIdentifier parentPath, final PathArgument child) {
checkArgument(parent != null, "Object should not be null.");
checkArgument(child != null, "Child argument should not be null");
Class<? extends DataContainer> parentClass = parent.getImplementedInterface();
return resolveReadStrategy(parentClass, child.getType()).readUsingPathArgument(parent, child, parentPath);
}
- private static DataObjectReadingStrategy resolveReadStrategy(Class<? extends DataContainer> parentClass,
- Class<? extends DataContainer> type) {
+ private static DataObjectReadingStrategy resolveReadStrategy(final Class<? extends DataContainer> parentClass,
+ final Class<? extends DataContainer> type) {
DataObjectReadingStrategy strategy = createReadStrategy(parentClass, type);
// FIXME: Add caching of strategies
return strategy;
}
- private static DataObjectReadingStrategy createReadStrategy(Class<? extends DataContainer> parent,
- Class<? extends DataContainer> child) {
+ private static DataObjectReadingStrategy createReadStrategy(final Class<? extends DataContainer> parent,
+ final Class<? extends DataContainer> child) {
if (Augmentable.class.isAssignableFrom(parent) && Augmentation.class.isAssignableFrom(child)) {
return REAUSABLE_AUGMENTATION_READING_STRATEGY;
return new ContainerReadingStrategy(parent, child);
}
- private static Method resolveGetterMethod(Class<? extends DataContainer> parent, Class<?> child) {
+ private static Method resolveGetterMethod(final Class<? extends DataContainer> parent, final Class<?> child) {
String methodName = "get" + child.getSimpleName();
try {
return parent.getMethod(methodName);
private final Method getterMethod;
@SuppressWarnings("unchecked")
- public DataObjectReadingStrategy(Class parentType, Class childType) {
+ public DataObjectReadingStrategy(final Class parentType, final Class childType) {
super();
checkArgument(DataContainer.class.isAssignableFrom(parentType));
checkArgument(DataContainer.class.isAssignableFrom(childType));
}
@SuppressWarnings("unchecked")
- public DataObjectReadingStrategy(Class parentType, Class childType, Method getter) {
+ public DataObjectReadingStrategy(final Class parentType, final Class childType, final Method getter) {
this.parentType = parentType;
this.childType = childType;
this.getterMethod = getter;
@SuppressWarnings("rawtypes")
private static class ContainerReadingStrategy extends DataObjectReadingStrategy {
- public ContainerReadingStrategy(Class<? extends DataContainer> parent, Class<? extends DataContainer> child) {
+ public ContainerReadingStrategy(final Class<? extends DataContainer> parent, final Class<? extends DataContainer> child) {
super(parent, child);
checkArgument(child.isAssignableFrom(getGetterMethod().getReturnType()));
}
@Override
- public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(DataContainer parent,
- PathArgument childArgument, InstanceIdentifier parentPath) {
+ public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent,
+ final PathArgument childArgument, final InstanceIdentifier parentPath) {
final DataContainer result = read(parent, childArgument.getType());
if (result != null) {
@SuppressWarnings("unchecked")
}
@Override
- public DataContainer read(DataContainer parent, Class<?> childType) {
+ public DataContainer read(final DataContainer parent, final Class<?> childType) {
try {
Object potentialData = getGetterMethod().invoke(parent);
checkState(potentialData instanceof DataContainer);
@SuppressWarnings("rawtypes")
private static class ListItemReadingStrategy extends DataObjectReadingStrategy {
- public ListItemReadingStrategy(Class<? extends DataContainer> parent, Class child) {
+ public ListItemReadingStrategy(final Class<? extends DataContainer> parent, final Class child) {
super(parent, child);
checkArgument(Iterable.class.isAssignableFrom(getGetterMethod().getReturnType()));
}
@Override
- public DataContainer read(DataContainer parent, Class<?> childType) {
+ public DataContainer read(final DataContainer parent, final Class<?> childType) {
// This will always fail since we do not have key.
return null;
}
@SuppressWarnings("unchecked")
@Override
- public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(DataContainer parent,
- PathArgument childArgument, InstanceIdentifier builder) {
+ public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent,
+ final PathArgument childArgument, final InstanceIdentifier builder) {
try {
Object potentialList = getGetterMethod().invoke(parent);
if (potentialList instanceof Iterable) {
return Collections.emptyMap();
}
- private Map<InstanceIdentifier, DataContainer> readAll(Iterable<Identifiable> dataList,
- InstanceIdentifier parentPath) {
+ private Map<InstanceIdentifier, DataContainer> readAll(final Iterable<Identifiable> dataList,
+ final InstanceIdentifier parentPath) {
Builder<InstanceIdentifier, DataContainer> result = ImmutableMap
.<InstanceIdentifier, DataContainer> builder();
for (Identifiable item : dataList) {
}
@SuppressWarnings("unchecked")
- private Map<InstanceIdentifier, DataContainer> readUsingIdentifiableItem(Iterable<Identifiable> dataList,
- IdentifiableItem childArgument, InstanceIdentifier parentPath) {
+ private Map<InstanceIdentifier, DataContainer> readUsingIdentifiableItem(final Iterable<Identifiable> dataList,
+ final IdentifiableItem childArgument, final InstanceIdentifier parentPath) {
final Identifier<?> key = childArgument.getKey();
for (Identifiable item : dataList) {
if (key.equals(item.getKey()) && item instanceof DataContainer) {
@SuppressWarnings("rawtypes")
@Override
- public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(DataContainer parent,
- PathArgument childArgument, InstanceIdentifier builder) {
+ public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent,
+ final PathArgument childArgument, final InstanceIdentifier builder) {
checkArgument(childArgument instanceof Item<?>, "Path Argument must be Item without keys");
DataContainer aug = read(parent, childArgument.getType());
if (aug != null) {
}
@Override
- public DataContainer read(DataContainer parent, Class<?> childType) {
+ public DataContainer read(final DataContainer parent, final Class<?> childType) {
checkArgument(Augmentation.class.isAssignableFrom(childType), "Parent must be Augmentable.");
checkArgument(parent instanceof Augmentable<?>, "Parent must be Augmentable.");
* @throws IllegalArgumentException
* if parent argument is bigger than child
*/
- private static <P, C> List<C> subList(Iterable<P> parent, Iterable<C> child) {
+ private static <P, C> List<C> subList(final Iterable<P> parent, final Iterable<C> child) {
Iterator<P> iParent = parent.iterator();
List<C> result = new ArrayList<>();
for (C arg : child) {
.build(new CacheLoader<Class<? extends NotificationListener>, NotificationListenerInvoker>() {
@Override
- public NotificationListenerInvoker load(Class<? extends NotificationListener> key) throws Exception {
+ public NotificationListenerInvoker load(final Class<? extends NotificationListener> key) throws Exception {
return createInvoker(key);
}
private final Map<QName, MethodHandle> methodInvokers;
- public NotificationListenerInvoker(Map<QName, MethodHandle> map) {
+ public NotificationListenerInvoker(final Map<QName, MethodHandle> map) {
this.methodInvokers = map;
}
* supplied RPC type.
*
*/
- public static NotificationListenerInvoker from(Class<? extends NotificationListener> type) {
+ public static NotificationListenerInvoker from(final Class<? extends NotificationListener> type) {
Preconditions.checkArgument(type.isInterface());
Preconditions.checkArgument(BindingReflections.isBindingClass(type));
return INVOKERS.getUnchecked(type);
* Input data for RPC.
*
*/
- public void invokeNotification(@Nonnull NotificationListener impl, @Nonnull QName rpcName,
- @Nullable DataContainer input) {
+ public void invokeNotification(@Nonnull final NotificationListener impl, @Nonnull final QName rpcName,
+ @Nullable final DataContainer input) {
Preconditions.checkNotNull(impl, "implemetation must be supplied");
MethodHandle invoker = methodInvokers.get(rpcName);
Preconditions.checkArgument(invoker != null, "Supplied notification is not valid for implementation %s", impl);
}
}
- private static NotificationListenerInvoker createInvoker(Class<? extends NotificationListener> key) {
+ private static NotificationListenerInvoker createInvoker(final Class<? extends NotificationListener> key) {
return new NotificationListenerInvoker(createInvokerMap(key));
}
- private static Map<QName, MethodHandle> createInvokerMap(Class<? extends NotificationListener> key) {
- Builder<QName, MethodHandle> ret = ImmutableMap.<QName, MethodHandle> builder();
+ private static Map<QName, MethodHandle> createInvokerMap(final Class<? extends NotificationListener> key) {
+ Builder<QName, MethodHandle> ret = ImmutableMap.<QName, MethodHandle>builder();
for (Method method : key.getMethods()) {
if (BindingReflections.isNotificationCallback(method)) {
final RpcError... errors) {
super(Preconditions.checkNotNull(message), cause);
- if( errors != null && errors.length > 0 ) {
+ if (errors != null && errors.length > 0) {
errorList = ImmutableList.<RpcError>copyOf( Arrays.asList( errors ) );
- }
- else {
+ } else {
// Add a default RpcError.
errorList = ImmutableList.of(RpcResultBuilder.newError(ErrorType.APPLICATION, null,
getMessage(), null, null, getCause()));
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
-
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
}
@Override
- public String toString(){
+ public String toString() {
return "RpcResult [successful=" + successful + ", result="
+ result + ", errors=" + errors + "]";
}
}
@Override
- public String getMessage(){
+ public String getMessage() {
return message;
}
}
@Override
- public String toString(){
+ public String toString() {
return "RpcError [message=" + message + ", severity="
+ severity + ", errorType=" + errorType + ", tag=" + tag
+ ", applicationTag=" + applicationTag + ", info=" + info
* @param result the result value
*/
public static <T> RpcResultBuilder<T> success( final T result ) {
- return new RpcResultBuilder<T>( true, result );
+ return new RpcResultBuilder<T>( true, result );
}
/**
private void addError( final RpcError error ) {
- if( errors == null ) {
+ if (errors == null) {
errors = new ImmutableList.Builder<RpcError>();
}
* @param errors the list of RpcErrors
*/
public RpcResultBuilder<T> withRpcErrors( final Collection<RpcError> errors ) {
- if( errors != null ) {
- for( RpcError error: errors ) {
+ if (errors != null) {
+ for (RpcError error : errors) {
addError( error );
}
}
protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
final Version version) {
// For Node Containers - merge is same as subtree change - we only replace children.
- return applySubtreeChange(modification, currentMeta, version);
+ return applyTouch(modification, currentMeta, version);
}
@Override
- public TreeNode applySubtreeChange(final ModifiedNode modification,
+ public TreeNode applyTouch(final ModifiedNode modification,
final TreeNode currentMeta, final Version version) {
final MutableTreeNode newMeta = currentMeta.mutable();
newMeta.setSubtreeVersion(version);
}
@Override
- protected void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+ protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
final Optional<TreeNode> current) throws DataValidationFailedException {
if (!modification.getOriginal().isPresent() && !current.isPresent()) {
throw new ModifiedNodeDoesNotExistException(path, String.format("Node %s does not exist. Cannot apply modification to its children.", path));
}
@Override
- protected final TreeNode applySubtreeChange(final ModifiedNode modification,
+ protected final TreeNode applyTouch(final ModifiedNode modification,
final TreeNode currentMeta, final Version version) {
throw new UnsupportedOperationException("Node " + schema.getPath()
+ "is leaf type node. Subtree change is not allowed.");
}
@Override
- protected final void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+ protected final void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
final Optional<TreeNode> current) throws IncorrectDataStructureException {
throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
}
checkDeleteApplicable(modification, current);
break;
case TOUCH:
- checkSubtreeModificationApplicable(path, modification, current);
+ checkTouchApplicable(path, modification, current);
break;
case WRITE:
checkWriteApplicable(path, modification, current);
case TOUCH:
Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification",
modification);
- return modification.setSnapshot(Optional.of(applySubtreeChange(modification, currentMeta.get(),
+ return modification.setSnapshot(Optional.of(applyTouch(modification, currentMeta.get(),
version)));
case MERGE:
final TreeNode result;
* @param version New subtree version of parent node
* @return A sealed TreeNode representing applied operation.
*/
- protected abstract TreeNode applySubtreeChange(ModifiedNode modification, TreeNode currentMeta, Version version);
+ protected abstract TreeNode applyTouch(ModifiedNode modification, TreeNode currentMeta, Version version);
/**
*
* @throws ConflictingModificationAppliedException If subtree was changed in conflicting way
* @throws IncorrectDataStructureException If subtree modification is not applicable (e.g. leaf node).
*/
- protected abstract void checkSubtreeModificationApplicable(YangInstanceIdentifier path, final NodeModification modification,
+ protected abstract void checkTouchApplicable(YangInstanceIdentifier path, final NodeModification modification,
final Optional<TreeNode> current) throws DataValidationFailedException;
protected abstract void verifyWrittenStructure(NormalizedNode<?, ?> writtenValue);
}
@Override
- protected TreeNode applySubtreeChange(final ModifiedNode modification,
+ protected TreeNode applyTouch(final ModifiedNode modification,
final TreeNode currentMeta, final Version version) {
throw new UnsupportedOperationException("UnkeyedList does not support subtree change.");
}
}
@Override
- protected void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+ protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
final Optional<TreeNode> current) throws IncorrectDataStructureException {
throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
}
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
package org.opendaylight.yangtools.yang.model.api;
import com.google.common.base.Optional;
-
import java.util.List;
/**
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.yangtools.yang.model.api;
import com.google.common.base.Optional;
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.yangtools.yang.model.api;
/**
-package org.opendaylight.yangtools.yang.model.api;
-
-import java.net.URI;
-import java.util.Date;
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+package org.opendaylight.yangtools.yang.model.api;
+
+import java.net.URI;
+import java.util.Date;
+
public interface NamespaceRevisionAware {
URI getNamespace();
-
/* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
public interface ModuleStatement extends DeclaredStatement<String>, ModuleHeaderGroup, LinkageGroup, MetaGroup,
- RevisionGroup, BodyGroup
-
- {
+ RevisionGroup, BodyGroup {
@Nonnull String getName();
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.CheckedFuture;
-
import java.util.Collection;
-
import javax.annotation.Nonnull;
-
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.CheckedFuture;
-
import javax.annotation.Nonnull;
-
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
private final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
private final Collection<SourceIdentifier> resolvedSources;
- public SchemaResolutionException(final @Nonnull String message) {
+ public SchemaResolutionException(@Nonnull final String message) {
this(message, (Throwable)null);
}
- public SchemaResolutionException(final @Nonnull String message, final Throwable cause) {
+ public SchemaResolutionException(@Nonnull final String message, final Throwable cause) {
this(message, cause, Collections.<SourceIdentifier>emptySet(), ImmutableMultimap.<SourceIdentifier, ModuleImport>of());
}
- public SchemaResolutionException(final @Nonnull String message, final Collection<SourceIdentifier> resolvedSources,
+ public SchemaResolutionException(@Nonnull final String message, final Collection<SourceIdentifier> resolvedSources,
final @Nonnull Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
this(message, null, resolvedSources, unsatisfiedImports);
}
- public SchemaResolutionException(final @Nonnull String message, final Throwable cause,
+ public SchemaResolutionException(@Nonnull final String message, final Throwable cause,
@Nonnull final Collection<SourceIdentifier> resolvedSources,
@Nonnull final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
super(formatMessage(message, resolvedSources, unsatisfiedImports), cause);
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-
import java.util.Collections;
/**
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
import com.google.common.annotations.Beta;
-
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.concepts.Immutable;
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.io.ByteSource;
-
import java.io.IOException;
import java.io.InputStream;
-
import org.opendaylight.yangtools.concepts.Delegator;
/**
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.api;
import com.google.common.annotations.Beta;
-
import org.w3c.dom.Document;
/**
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
import com.google.common.annotations.Beta;
-
import org.opendaylight.yangtools.concepts.ListenerRegistration;
/**
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
import com.google.common.annotations.Beta;
-
import java.util.EventListener;
-
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
/**
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.CheckedFuture;
-
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
import com.google.common.annotations.Beta;
-
import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
import com.google.common.annotations.Beta;
-
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
final QName qname = Iterables.getFirst(schemaNode.getPath().getPathTowardsRoot(), null);
Preconditions.checkState(qname != null,
"Schema Path contains invalid state of path parts. " +
- "The Schema Path MUST contain at least ONE QName which defines namespace and Local name of path.");
+ "The Schema Path MUST contain at least ONE QName which defines namespace and Local name of path.");
return context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision());
}
RevisionAwareXPath pathStatement = typeDefinition.getPathStatement();
pathStatement = new RevisionAwareXPathImpl(stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute());
- final Module parentModule = SchemaContextUtil.findParentModule(schemaContext, schema);
+ Module parentModule = findParentModuleByType(schemaContext, schema);
final DataSchemaNode dataSchemaNode;
if(pathStatement.isAbsolute()) {
}
}
+ /**
+ * Returns parent Yang Module for specified Schema Context in which Schema
+ * Node is declared. If Schema Node is of type 'ExtendedType' it tries to find parent module
+ * in which the type was originally declared (needed for correct leafref path resolution). <br>
+ * If the Schema Node is not present in Schema Context the
+ * operation will return <code>null</code>. <br>
+ * If Schema Context or Schema Node contains <code>null</code> references
+ * the method will throw IllegalArgumentException
+ *
+ * @throws IllegalArgumentException
+ *
+ * @param schemaContext
+ * Schema Context
+ * @param schemaNode
+ * Schema Node
+ * @return Yang Module for specified Schema Context and Schema Node, if
+ * Schema Node is NOT present, the method will returns
+ * <code>null</code>
+ */
+ public static Module findParentModuleByType(final SchemaContext schemaContext, final SchemaNode schemaNode) {
+ Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!");
+ Preconditions.checkArgument(schemaNode != null, "Schema Node cannot be NULL!");
+ TypeDefinition<?> nodeType = null;
+
+ if (schemaNode instanceof LeafSchemaNode) {
+ nodeType = ((LeafSchemaNode) schemaNode).getType();
+ } else if (schemaNode instanceof LeafListSchemaNode) {
+ nodeType = ((LeafListSchemaNode) schemaNode).getType();
+ }
+
+ if (nodeType != null && nodeType instanceof ExtendedType) {
+ while (nodeType.getBaseType() instanceof ExtendedType) {
+ nodeType = nodeType.getBaseType();
+ }
+
+ QNameModule typeDefModuleQname = nodeType.getQName().getModule();
+
+ return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(),
+ typeDefModuleQname.getRevision());
+ }
+
+ return SchemaContextUtil.findParentModule(schemaContext, schemaNode);
+ }
+
/**
* Returns base type for {@code typeDefinition} which belongs to module specified via {@code qName}. This handle case
* when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other module as typedef