Skip to content

Commit

Permalink
Add new metadata types PluginManager and PluginData
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Nov 10, 2015
1 parent 3fb4589 commit 75c9536
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 84 deletions.
7 changes: 6 additions & 1 deletion src/main/java/com/speedment/Speedment.java
Expand Up @@ -24,6 +24,7 @@
import com.speedment.component.JavaTypeMapperComponent; import com.speedment.component.JavaTypeMapperComponent;
import com.speedment.component.LoggerFactoryComponent; import com.speedment.component.LoggerFactoryComponent;
import com.speedment.component.ManagerComponent; import com.speedment.component.ManagerComponent;
import com.speedment.component.PluginComponent;
import com.speedment.component.PrimaryKeyFactoryComponent; import com.speedment.component.PrimaryKeyFactoryComponent;
import com.speedment.component.ProjectComponent; import com.speedment.component.ProjectComponent;
import com.speedment.component.SqlTypeMapperComponent; import com.speedment.component.SqlTypeMapperComponent;
Expand Down Expand Up @@ -63,6 +64,7 @@ public interface Speedment {
* <li>{@link com.speedment.component.ConnectionPoolComponent ConnectionPoolComponent}</li> * <li>{@link com.speedment.component.ConnectionPoolComponent ConnectionPoolComponent}</li>
* <li>{@link com.speedment.component.StreamSupplierComponent StreamSupplierComponent}</li> * <li>{@link com.speedment.component.StreamSupplierComponent StreamSupplierComponent}</li>
* <li>{@link com.speedment.component.TypeMapperComponent TypeMapperComponent}</li> * <li>{@link com.speedment.component.TypeMapperComponent TypeMapperComponent}</li>
* <li>{@link com.speedment.component.PluginComponent PluginComponent}</li>
* </ul> * </ul>
* *
* @param <R> The intended return type * @param <R> The intended return type
Expand Down Expand Up @@ -156,5 +158,8 @@ default StreamSupplierComponent getStreamSupplierComponent() {
default TypeMapperComponent getTypeMapperComponent() { default TypeMapperComponent getTypeMapperComponent() {
return get(TypeMapperComponent.class); return get(TypeMapperComponent.class);
} }


default PluginComponent getPluginComponent() {
return get(PluginComponent.class);
}
} }
60 changes: 60 additions & 0 deletions src/main/java/com/speedment/component/PluginComponent.java
@@ -0,0 +1,60 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.component;

import com.speedment.annotation.Api;
import com.speedment.config.plugin.Plugin;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
*
* @author Emil Forslund
* @since 2.3
*/
@Api(version = "2.3")
public interface PluginComponent extends Component {

@Override
default Class<PluginComponent> getComponentClass() {
return PluginComponent.class;
}

/**
* Installs the specified plugin in this component.
*
* @param constructor the constructor for a plugin to install
*/
void install(Supplier<Plugin> constructor);

/**
* Streams over all the plugins installed in this component.
*
* @return all plugins
*/
Stream<Plugin> stream();

/**
* Retreive and return the plugin with the specified name. If it is
* not installed, return an empty optional.
*
* @param pluginName the name as returned by {@code Plugin#getName()}
* @return the installed plugin or empty
*/
Optional<Plugin> get(String pluginName);
}
Expand Up @@ -30,6 +30,11 @@
@Api(version="2.2") @Api(version="2.2")
public interface TypeMapperComponent extends Component { public interface TypeMapperComponent extends Component {


@Override
default Class<TypeMapperComponent> getComponentClass() {
return TypeMapperComponent.class;
}

/** /**
* Installs the specified type mapper in this component. * Installs the specified type mapper in this component.
* *
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/com/speedment/config/PluginData.java
@@ -0,0 +1,91 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.config;

import com.speedment.HasSpeedment;
import com.speedment.annotation.Api;
import com.speedment.annotation.External;
import com.speedment.component.PluginComponent;
import com.speedment.config.aspects.Child;
import com.speedment.config.aspects.Enableable;
import com.speedment.config.aspects.Parent;
import com.speedment.config.plugin.Plugin;
import com.speedment.exception.SpeedmentException;

/**
*
* @author Emil Forslund
* @since 2.3
*/
@Api(version = "2.3")
public interface PluginData extends Node, Enableable, HasSpeedment, Parent<Child<PluginData>>, Child<PluginManager> {

/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
default Class<PluginData> getInterfaceMainClass() {
return PluginData.class;
}

/**
* {@inheritDoc}
*/
@Override
default Class<PluginManager> getParentInterfaceMainClass() {
return PluginManager.class;
}

/**
* Sets the name of the {@link Plugin} that should be used to manage
* this node.
* <p>
* This property is editable in the GUI through reflection.
*
* @param pluginName the name as returned by {@link Plugin#getName()}
*/
@External(type = String.class)
void setPluginName(String pluginName);

/**
* Returns the name of the {@link Plugin} that should be used to manage
* this node.
* <p>
* This property is editable in the GUI through reflection.
*
* @return the name as returned by {@link Plugin#getName()}
*/
@External(type = String.class)
String getPluginName();

/**
* Contacts the {@link PluginComponent} to find a {@link Plugin} that
* matches the name specified by {@link #getPluginName()}.
*
* @return the plugin
* @throws SpeedmentException if the plugin could not be found
*/
default Plugin findPlugin() throws SpeedmentException {
return getSpeedment()
.get(PluginComponent.class)
.get(getPluginName())
.orElseThrow(() -> new SpeedmentException(
"Could not find plugin '" + getPluginName() + "'."
));
}
}
95 changes: 95 additions & 0 deletions src/main/java/com/speedment/config/PluginManager.java
@@ -0,0 +1,95 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.config;

import com.speedment.HasSpeedment;
import com.speedment.Speedment;
import com.speedment.annotation.Api;
import com.speedment.config.aspects.Child;
import com.speedment.config.aspects.Enableable;
import com.speedment.config.aspects.Parent;
import com.speedment.internal.core.config.PluginDataImpl;
import com.speedment.internal.core.config.PluginManagerImpl;
import java.util.function.Function;
import static java.util.Objects.requireNonNull;

/**
*
* @author Emil Forslund
* @since 2.3
*/
@Api(version = "2.3")
public interface PluginManager extends Node, Enableable, HasSpeedment, Parent<PluginData>, Child<ProjectManager> {

/**
* Factory holder.
*/
enum Holder {
HOLDER;
private Function<Speedment, PluginManager> provider = PluginManagerImpl::new;
}

/**
* Sets the instantiation method used to create new instances of this
* interface.
*
* @param provider the new constructor
*/
static void setSupplier(Function<Speedment, PluginManager> provider) {
Holder.HOLDER.provider = requireNonNull(provider);
}

/**
* Creates a new instance implementing this interface by using the class
* supplied by the default factory. To change implementation, please use the
* {@link #setSupplier(java.util.function.Function) setSupplier} method.
*
* @param speedment instance to use
* @return the new instance
*/
static PluginManager newPluginManager(Speedment speedment) {
return Holder.HOLDER.provider.apply(speedment);
}

/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
default Class<PluginManager> getInterfaceMainClass() {
return PluginManager.class;
}

/**
* {@inheritDoc}
*/
@Override
default Class<ProjectManager> getParentInterfaceMainClass() {
return ProjectManager.class;
}

/**
* Creates and adds a new {@link PluginData} as a child to this node in the
* configuration tree.
*
* @param speedment the {@link Speedment} instance
* @return the newly added child
*/
default PluginData addNewPluginData(Speedment speedment) {
return new PluginDataImpl(speedment);
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/speedment/config/ProjectManager.java
Expand Up @@ -17,6 +17,7 @@
package com.speedment.config; package com.speedment.config;


import com.speedment.annotation.Api; import com.speedment.annotation.Api;
import com.speedment.config.aspects.Child;
import com.speedment.config.aspects.Enableable; import com.speedment.config.aspects.Enableable;
import com.speedment.config.aspects.Parent; import com.speedment.config.aspects.Parent;


Expand All @@ -25,7 +26,7 @@
* @author pemi * @author pemi
*/ */
@Api(version = "2.2") @Api(version = "2.2")
public interface ProjectManager extends Node, Enableable, Parent<Project> { public interface ProjectManager extends Node, Enableable, Parent<Child<ProjectManager>> {


/** /**
* {@inheritDoc} * {@inheritDoc}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/speedment/config/plugin/Plugin.java
@@ -0,0 +1,50 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.config.plugin;

import com.speedment.annotation.Api;

/**
*
* @author Emil Forslund
* @since 2.3
*/
@Api(version = "2.3")
public interface Plugin {

/**
* Returns the name of this plugin as declared in the groovy file.
*
* @return the unique name
*/
String getName();

/**
* Returns the label of this plugin as shown visible to the user in
* the GUI.
*
* @return the label
*/
String getLabel();

/**
* Returns the path of the icon to use for this node in the GUI.
*
* @return the icon path
*/
String getIconPath();
}

0 comments on commit 75c9536

Please sign in to comment.