use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class XMLDataChannelDescriptorLoader method load.
@Override
public ConfigurationTree<DataChannelDescriptor> load(Resource configurationResource) throws ConfigurationException {
if (configurationResource == null) {
throw new NullPointerException("Null configurationResource");
}
URL configurationURL = configurationResource.getURL();
logger.info("Loading XML configuration resource from " + configurationURL);
final DataChannelDescriptor descriptor = new DataChannelDescriptor();
descriptor.setConfigurationSource(configurationResource);
descriptor.setName(nameMapper.configurationNodeName(DataChannelDescriptor.class, configurationResource));
try (InputStream in = configurationURL.openStream()) {
XMLReader parser = xmlReaderProvider.get();
LoaderContext loaderContext = new LoaderContext(parser, handlerFactory);
loaderContext.addDataMapListener(dataMap -> descriptor.getDataMaps().add(dataMap));
DataChannelHandler rootHandler = new DataChannelHandler(this, descriptor, loaderContext);
parser.setContentHandler(rootHandler);
parser.setErrorHandler(rootHandler);
InputSource input = new InputSource(in);
input.setSystemId(configurationURL.toString());
parser.parse(input);
loaderContext.dataChannelLoaded(descriptor);
} catch (Exception e) {
throw new ConfigurationException("Error loading configuration from %s", e, configurationURL);
}
// TODO: andrus 03/10/2010 - actually provide load failures here...
return new ConfigurationTree<>(descriptor, null);
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ProjectUtil method findObjAttributesForDbRelationship.
public static Collection<ObjAttribute> findObjAttributesForDbRelationship(ProjectController mediator, DbRelationship relationship) {
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
List<ObjAttribute> attributes = new ArrayList<>();
String[] dbAttrPathByDot;
if (domain != null) {
for (DataMap map : domain.getDataMaps()) {
for (ObjEntity entity : map.getObjEntities()) {
for (ObjAttribute objAttribute : entity.getAttributes()) {
if (objAttribute.getDbAttributePath() != null) {
dbAttrPathByDot = objAttribute.getDbAttributePath().split(Pattern.quote("."));
for (String partOfPath : dbAttrPathByDot) {
if (partOfPath.equals(relationship.getName())) {
attributes.add(objAttribute);
}
}
}
}
}
}
}
return attributes;
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ProjectUtil method findObjRelationshipsForDbRelationship.
public static Collection<ObjRelationship> findObjRelationshipsForDbRelationship(ProjectController mediator, DbRelationship relationship) {
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
List<ObjRelationship> objRelationships = new ArrayList<>();
if (domain != null) {
for (DataMap map : domain.getDataMaps()) {
for (ObjEntity entity : map.getObjEntities()) {
for (ObjRelationship objRelationship : entity.getRelationships()) {
if (objRelationship.getDbRelationships().contains(relationship)) {
objRelationships.add(objRelationship);
}
}
}
}
}
return objRelationships;
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class AttributeDisplayEventType method fireLastDisplayEvent.
@Override
public void fireLastDisplayEvent() {
DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
if (!dataChannel.getName().equals(preferences.getDomain())) {
return;
}
DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(preferences.getNode());
DataMap dataMap = dataChannel.getDataMap(preferences.getDataMap());
if (dataMap == null) {
return;
}
Entity entity = getLastEntity(dataMap);
if (entity == null) {
return;
}
Attribute[] attributes = getLastEntityAttributes(entity);
EntityDisplayEvent entityDisplayEvent = new EntityDisplayEvent(this, entity, dataMap, dataNode, dataChannel);
AttributeDisplayEvent attributeDisplayEvent = new AttributeDisplayEvent(this, attributes, entity, dataMap, dataChannel);
if (entity instanceof ObjEntity) {
controller.fireObjEntityDisplayEvent(entityDisplayEvent);
controller.fireObjAttributeDisplayEvent(attributeDisplayEvent);
} else if (entity instanceof DbEntity) {
controller.fireDbEntityDisplayEvent(entityDisplayEvent);
controller.fireDbAttributeDisplayEvent(attributeDisplayEvent);
}
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DataNodeDisplayEventType method fireLastDisplayEvent.
@Override
public void fireLastDisplayEvent() {
DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
if (!dataChannel.getName().equals(preferences.getDomain())) {
return;
}
DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(preferences.getNode());
if (dataNode == null) {
return;
}
DataNodeDisplayEvent dataNodeDisplayEvent = new DataNodeDisplayEvent(this, dataChannel, dataNode);
controller.fireDataNodeDisplayEvent(dataNodeDisplayEvent);
}
Aggregations