Java Code Examples for org.apache.wicket.util.lang.Args#notNull()

The following examples show how to use org.apache.wicket.util.lang.Args#notNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebSocketRequestHandler.java    From onedev with MIT License 6 votes vote down vote up
@Override
public void push(byte[] message, int offset, int length)
{
	if (connection.isOpen())
	{
		Args.notNull(message, "message");
		try
		{
			connection.sendMessage(message, offset, length);
		} catch (IOException iox)
		{
			LOG.error("An error occurred while pushing binary message.", iox);
		}
	}
	else
	{
		LOG.warn("The websocket connection is already closed. Cannot push the binary message '{}'", message);
	}
}
 
Example 2
Source File: WebSocketRequestHandler.java    From onedev with MIT License 6 votes vote down vote up
@Override
public void add(Component... components)
{
	for (final Component component : components)
	{
		Args.notNull(component, "component");

		if (component.getOutputMarkupId() == false)
		{
			throw new IllegalArgumentException(
					"cannot update component that does not have setOutputMarkupId property set to true. Component: " +
							component.toString());
		}
		add(component, component.getMarkupId());
	}
}
 
Example 3
Source File: GridsterWidgetBehavior.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public final void bind(final Component hostComponent)
{
	Args.notNull(hostComponent, "hostComponent");

	if (component != null)
	{
		throw new IllegalStateException("this kind of handler cannot be attached to " +
			"multiple components; it is already attached to component " + component +
			", but component " + hostComponent + " wants to be attached too");
	}
	if(!(hostComponent instanceof AbstractWidget))
	{
		throw new IllegalStateException("This behaviour can be attached only to "+AbstractWidget.class.getSimpleName()+
										", but this one: "+hostComponent.getClass().getName());
	}

	component = (AbstractWidget<?>)hostComponent;
}
 
Example 4
Source File: SimpleWebSocketConnectionRegistry.java    From onedev with MIT License 6 votes vote down vote up
@Override
public IWebSocketConnection getConnection(Application application, String sessionId, IKey key)
{
	Args.notNull(application, "application");
	Args.notNull(sessionId, "sessionId");
	Args.notNull(key, "key");

	IWebSocketConnection connection = null;
	ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY);
	if (connectionsBySession != null)
	{
		ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId);
		if (connectionsByPage != null)
		{
			connection = connectionsByPage.get(key);
		}
	}
	return connection;
}
 
Example 5
Source File: SimpleWebSocketConnectionRegistry.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Returns a collection of currently active websockets. The connections might close at any time.
 *
 * @param application
 *          The application
 * @return a collection of currently active websockets
 */
public Collection<IWebSocketConnection> getConnections(Application application)
{
	Args.notNull(application, "application");

	Collection<IWebSocketConnection> connections = new ArrayList<>();
	ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY);
	if (connectionsBySession != null)
	{
		for (ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage : connectionsBySession.values())
		{
			connections.addAll(connectionsByPage.values());
		}
	}
	return connections;
}
 
Example 6
Source File: ExtendedWicketTester.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Process a component. A web page will be automatically created with the {@code pageMarkup}
 * provided. In case pageMarkup is null, the markup will be automatically created with
 * {@link #createFormPageMarkup(String, String)}.
 * <p>
 *     <strong>Note</strong>: the instantiated component will have an auto-generated id. To
 *     reach any of its children use their relative path to the component itself. For example
 *     if the started component has a child a Link component with id "link" then after starting
 *     the component you can click it with: <code>tester.clickLink("link")</code>
 * </p>
 * 
 * @param <C>
 *            the type of the component
 * 
 * @param componentClass
 *            the class of the component to be tested
 * @param inputType
 *            the type of HTML input to be associated with the component to be tested
 * @param pageMarkup
 *            the markup for the Page that will be automatically created. May be {@code null}.
 * @return The component processed
 */
@SuppressWarnings("deprecation")
public final <C extends Component> C startComponentInForm(final Class<C> componentClass,
	final String inputType, final IMarkupFragment pageMarkup)
{
	Args.notNull(componentClass, "componentClass");

	// Create the component instance from the class
	C comp = null;
	try
	{
		Constructor<C> c = componentClass.getConstructor(String.class);
		comp = c.newInstance(ComponentInForm.ID);
		componentInForm = new ComponentInForm();
		componentInForm.component = comp;
		componentInForm.isInstantiated = true;
	}
	catch (Exception e)
	{
		fail(String.format("Cannot instantiate component with type '%s' because of '%s'",
			componentClass.getName(), e.getMessage()));
	}

	// process the component
	return startComponentInForm(comp, inputType, pageMarkup);
}
 
Example 7
Source File: BasicResourceReferenceMapper.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Construct.
 * 
 * @param pageParametersEncoder
 * @param cachingStrategy
 */
public BasicResourceReferenceMapper(IPageParametersEncoder pageParametersEncoder,
	IProvider<? extends IResourceCachingStrategy> cachingStrategy)
{
	this.pageParametersEncoder = Args.notNull(pageParametersEncoder, "pageParametersEncoder");
	this.cachingStrategy = cachingStrategy;
}
 
Example 8
Source File: Strings.java    From onedev with MIT License 5 votes vote down vote up
/**
 * convert byte array to hex string
 * 
 * @param bytes
 *          bytes to convert to hexadecimal representation
 *
 * @return hex string 
 */
public static String toHexString(byte[] bytes)
{
	Args.notNull(bytes, "bytes");

	final StringBuilder hex = new StringBuilder(bytes.length << 1);

	for (final byte b : bytes)
	{
		hex.append(toHex(b >> 4));
		hex.append(toHex(b));
	}
	return hex.toString();
}
 
Example 9
Source File: FormComponent.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Adds a validator to this form component.
 * 
 * @param validators
 *            The validator(s) to be added
 * @return This
 * @throws IllegalArgumentException
 *             if validator is null
 * @see IValidator
 */
@SafeVarargs
public final FormComponent<T> add(final IValidator<? super T>... validators)
{
	Args.notNull(validators, "validators");

	for (IValidator<? super T> validator : validators)
	{
		add(validator);
	}

	// return this for chaining
	return this;
}
 
Example 10
Source File: DynamicPropertyValueModel.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
public DynamicPropertyValueModel(IModel<ODocument> docModel, IModel<OProperty> propertyModel, Class<? extends T> valueType)
{
	Args.notNull(docModel, "documentModel");
	this.docModel = docModel;
	this.propertyModel = propertyModel;
	this.valueType = valueType;
}
 
Example 11
Source File: GenericTablePanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private GenericTablePanel(String id, List<? extends IColumn<K, String>> columns,
                          ISortableDataProvider<K, String> provider, int rowsPerRange, boolean filtered) {
    super(id);
    Args.notNull(columns, "columns");
    Args.notNull(provider, "provider");
    setOutputMarkupPlaceholderTag(true);
    dataTable = new OrienteerDataTable<>("table", columns, provider, rowsPerRange);
    if (filtered) {
        FilterForm<OQueryModel<K>> filterForm = createFilterForm("form", (IFilterStateLocator<OQueryModel<K>>) provider);
        filterForm.setOutputMarkupPlaceholderTag(true);
        dataTable.addFilterForm(filterForm);
        filterForm.add(dataTable);
        AjaxFallbackButton button = new AjaxFallbackButton("submit", filterForm) {};
        filterForm.setDefaultButton(button);
        filterForm.enableFocusTracking(button);
        filterForm.add(button);
        filterForm.add(dataTable);
        add(filterForm);
    } else {
        Form form = new Form("form");
        form.add(dataTable);
        form.add(new AjaxFallbackButton("submit", form) {}.setVisible(false));
        add(form);
    }
    add(new EmptyPanel("error").setVisible(false));
}
 
Example 12
Source File: SimpleVisualizer.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public SimpleVisualizer(String name, boolean extended, Class<? extends Component> viewComponentClass, 
							Class<? extends Component> editComponentClass, Collection<OType> supportedTypes)
{
	super(name, extended, supportedTypes);
	Args.notNull(name, "name");
	Args.notNull(viewComponentClass, "viewComponentClass");
	Args.notNull(editComponentClass, "editComponentClass");
	Args.notNull(supportedTypes, "supportedTypes");
	Args.notEmpty(supportedTypes, "supportedTypes");
	this.viewComponentClass = viewComponentClass;
	this.editComponentClass = editComponentClass;
}
 
Example 13
Source File: FunctionModel.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
public FunctionModel(IModel<F> fromModel, SerializableFunction<? super F, ? extends T> function, SerializableFunction<? super T, ? extends F> backwardFunction) {
	super(fromModel);
	Args.notNull(function, "Function should be specified");
	this.function = SerializableConverter.of(function, backwardFunction);
}
 
Example 14
Source File: InfinitePagingDataTable.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void addToolbar(final InfinitePagingDataTableToolbar toolbar, final ToolbarsContainer container)
{
	Args.notNull(toolbar, "toolbar");
	container.getRepeatingView().add(toolbar);
}
 
Example 15
Source File: InfinitePagingDataViewBase.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public InfinitePagingDataViewBase(String id, InfiniteDataProvider<T> dataProvider)
{
	super(id);
	this.dataProvider = Args.notNull(dataProvider, "dataProvider");
}
 
Example 16
Source File: SimpleWebSocketConnectionRegistry.java    From onedev with MIT License 4 votes vote down vote up
@Override
public void setConnection(Application application, String sessionId, IKey key, IWebSocketConnection connection)
{
	Args.notNull(application, "application");
	Args.notNull(sessionId, "sessionId");
	Args.notNull(key, "key");

	ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY);
	if (connectionsBySession == null)
	{
		synchronized (KEY)
		{
			connectionsBySession = application.getMetaData(KEY);
			if (connectionsBySession == null)
			{
				connectionsBySession = Generics.newConcurrentHashMap();
				application.setMetaData(KEY, connectionsBySession);
			}
		}
	}

	ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId);
	if (connectionsByPage == null && connection != null)
	{
		connectionsByPage = connectionsBySession.get(sessionId);
		if (connectionsByPage == null)
		{
			connectionsByPage = Generics.newConcurrentHashMap();
			ConcurrentMap<IKey, IWebSocketConnection> old = connectionsBySession.putIfAbsent(sessionId, connectionsByPage);
			if (old != null)
			{
				connectionsByPage = old;
			}
		}
	}

	if (connection != null)
	{
		connectionsByPage.put(key, connection);
	}
	else if (connectionsByPage != null)
	{
		connectionsByPage.remove(key);
		if (connectionsByPage.isEmpty())
		{
			connectionsBySession.remove(sessionId);
		}
	}
}
 
Example 17
Source File: ListOIndexesModel.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
public ListOIndexesModel(final IModel<OClass> oClassModel, final IModel<Boolean> allIndexesModel)
{
	Args.notNull(oClassModel, "oClassModel");
	this.oClassModel = oClassModel;
	this.allIndexesModel = allIndexesModel;
}
 
Example 18
Source File: AbstractModeMetaPanel.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
protected Component resolveComponent(String id, C critery) {
	K mode = getModeObject();
	Args.notNull(mode, "mode");
	return resolveComponent(id, getEffectiveMode(mode, critery), critery);
}
 
Example 19
Source File: WebSocketRequestHandler.java    From onedev with MIT License 4 votes vote down vote up
public WebSocketRequestHandler(final Component component, final IWebSocketConnection connection)
{
	this.page = Args.notNull(component, "component").getPage();
	this.connection = Args.notNull(connection, "connection");
}
 
Example 20
Source File: SassResourceReferenceFactory.java    From webanno with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param delegate
 *            A factory to delegate the creation of the ResourceReference if the key's name
 *            doesn't have extension <em>.scss</em> or <em>.sass</em>
 */
public SassResourceReferenceFactory(IResourceReferenceFactory delegate)
{
    this.delegate = Args.notNull(delegate, "delegate");
}