📄 fragmentimpl.java
字号:
if (eName == null) throw new XBRLException("An element name must be specified.");
if (getBuilder() != null) {
getBuilder().removeMetadataElement(eName, attributes);
return;
}
// If the fragment has been stored update the data store
Element element = this.getMetadataRootElement();
if (element == null) throw new XBRLException("The metadata does not contain a root element.");
NodeList children = element.getElementsByTagNameNS(Constants.XBRLAPINamespace,eName);
for (int i=0; i<children.getLength(); i++) {
boolean match = true;
Element child = (Element) children.item(i);
Iterator<String> attributeNames = attributes.keySet().iterator();
while (attributeNames.hasNext()) {
String aName = attributeNames.next();
String aValue = attributes.get(aName);
if (aName != null) {
if (aValue == null) throw new XBRLException("A metadata element is being checked but attribute, " + aName + ", has a null value.");
if (! child.getAttribute(aName).equals(aValue)) {
match = false;
}
} else throw new XBRLException("A metadata element is being checked against an attribute with a null name.");
}
if (match) {
element.removeChild(child);
break;
}
}
updateStore();
}
/**
* @see org.xbrlapi.Fragment#getURL()
*/
public String getURL() throws XBRLException {
return this.getMetaAttribute("url");
}
/**
* @see org.xbrlapi.Fragment#setURL(String)
*/
public void setURL(String url) throws XBRLException {
this.setMetaAttribute("url",url);
}
/**
* @see org.xbrlapi.Fragment#getReferencingLocators()
*/
public FragmentList<Locator> getReferencingLocators() throws XBRLException {
// Construct the Query
String predicate = Constants.XBRLAPIPrefix + ":" + "data/link:loc and @targetDocumentURL='"+ getURL() +"' and (";
NodeList xptrs = this.getMetadataRootElement().getElementsByTagNameNS(Constants.XBRLAPINamespace,"xptr");
for (int i=0; i<xptrs.getLength(); i++) {
String value = ((Element) xptrs.item(i)).getAttribute("value").trim();
predicate += "@targetPointerValue='" + value +"'";
if (i == (xptrs.getLength()-1))
predicate += ")";
else
predicate += " or ";
}
String query = "/"+ Constants.XBRLAPIPrefix+ ":" + "fragment[" + predicate + "]";
return getStore().<Locator>query(query);
}
/**
* TODO Add methods to get labels based on language and role.
* @see org.xbrlapi.Fragment#getLabels()
*/
public FragmentList<LabelResource> getLabels() throws XBRLException {
Networks labelNetworks = this.getNetworksWithArcrole(Constants.LabelArcRole);
FragmentList<LabelResource> labels = labelNetworks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.LabelArcRole);
Networks genericLabelNetworks = this.getNetworksWithArcrole(Constants.GenericLabelArcRole);
FragmentList<LabelResource> genericLabels = genericLabelNetworks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.GenericLabelArcRole);
labels.addAll(genericLabels);
return labels;
}
/**
* @see org.xbrlapi.Fragment#getLabelsWithRole(String)
*/
public FragmentList<LabelResource> getLabelsWithRole(String role) throws XBRLException {
Networks networks = this.getNetworksWithArcrole(Constants.LabelArcRole);
FragmentList<LabelResource> result = new FragmentListImpl<LabelResource>();
FragmentList<LabelResource> labels = networks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.LabelArcRole);
for (LabelResource label: labels) {
String r = label.getResourceRole();
if (r != null) {
if (r.equals(role)) result.add(label);
}
}
networks = this.getNetworksWithArcrole(Constants.GenericLabelArcRole);
labels = networks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.GenericLabelArcRole);
for (LabelResource label: labels) {
String r = label.getResourceRole();
if (r != null) {
if (r.equals(role)) result.add(label);
}
}
return result;
}
/**
* @see org.xbrlapi.Fragment#getLabelsWithLanguage(String)
*/
public FragmentList<LabelResource> getLabelsWithLanguage(String language) throws XBRLException {
Networks networks = this.getNetworksWithArcrole(Constants.LabelArcRole);
FragmentList<LabelResource> result = new FragmentListImpl<LabelResource>();
FragmentList<LabelResource> labels = networks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.LabelArcRole);
for (LabelResource label: labels) {
String l = label.getLanguage();
if (l != null) {
if (label.getLanguage().equals(language)) result.add(label);
}
}
networks = this.getNetworksWithArcrole(Constants.GenericLabelArcRole);
labels = networks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.GenericLabelArcRole);
for (LabelResource label: labels) {
String l = label.getLanguage();
if (l != null) {
if (label.getLanguage().equals(language)) result.add(label);
}
}
return result;
}
/**
* @see org.xbrlapi.Fragment#getLabelsWithLanguageAndRole(String, String)
*/
public FragmentList<LabelResource> getLabelsWithLanguageAndRole(String language, String role) throws XBRLException {
Networks networks = this.getNetworksWithArcrole(Constants.LabelArcRole);
FragmentList<LabelResource> result = new FragmentListImpl<LabelResource>();
FragmentList<LabelResource> labels = networks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.LabelArcRole);
for (LabelResource label: labels) {
String l = label.getLanguage();
String r = label.getResourceRole();
if (l != null && r != null) {
if (l.equals(language) && r.equals(role)) result.add(label);
}
}
networks = this.getNetworksWithArcrole(Constants.GenericLabelArcRole);
labels = networks.<LabelResource>getTargetFragments(this.getFragmentIndex(),Constants.GenericLabelArcRole);
for (LabelResource label: labels) {
String l = label.getLanguage();
String r = label.getResourceRole();
if (l != null && r != null) {
if (l.equals(language) && r.equals(role)) result.add(label);
}
}
return result;
}
/**
* TODO Add methods to get references based on language and role.
* @see org.xbrlapi.Fragment#getReferences()
*/
public FragmentList<ReferenceResource> getReferences() throws XBRLException {
Networks networks = this.getNetworks();
FragmentList<ReferenceResource> references = networks.<ReferenceResource>getTargetFragments(this.getFragmentIndex(),Constants.ReferenceArcRole);
references.addAll(networks.<ReferenceResource>getTargetFragments(this.getFragmentIndex(),Constants.GenericReferenceArcRole));
return references;
}
/**
* @see org.xbrlapi.Fragment#getNetworks()
*/
public Networks getNetworks() throws XBRLException {
logger.debug("Getting networks for fragment " + getFragmentIndex());
Networks networks = new NetworksImpl();
Relationship relationship = null;
// If we have a resource, it could be related directly via arcs to relatives.
if (this.isa("org.xbrlapi.impl.ResourceImpl")) {
FragmentList<Arc> arcs = ((ArcEnd) this).getArcsFrom();
logger.debug("Fragment " + this.getFragmentIndex() + " is a XLink resource with " + arcs.getLength() + " direct arcs FROM it.");
for (Arc arc: arcs) {
FragmentList<ArcEnd> targets = arc.getTargetFragments();
for (ArcEnd end: targets) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment target = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,this,target);
} else {
relationship = new RelationshipImpl(arc,this,end);
}
networks.addRelationship(relationship);
}
}
arcs = ((ArcEnd) this).getArcsTo();
logger.debug("Fragment " + this.getFragmentIndex() + " is a XLink resource with " + arcs.getLength() + " direct arcs TO it.");
for (Arc arc: arcs) {
FragmentList<ArcEnd> sources = arc.getSourceFragments();
for (ArcEnd end: sources) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment source = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,source,this);
} else {
relationship = new RelationshipImpl(arc,end,this);
}
networks.addRelationship(relationship);
}
}
}
// Next get the locators for the fragment to find indirect relatives
FragmentList<Locator> locators = this.getReferencingLocators();
logger.debug("Fragment " + this.getFragmentIndex() + " has " + locators.getLength() + " locators locating it.");
for (Locator locator: locators) {
FragmentList<Arc> arcs = locator.getArcsFrom();
logger.debug("Locator " + locator.getFragmentIndex() + " has " + arcs.getLength() + " direct arcs FROM it.");
for (Arc arc: arcs) {
FragmentList<ArcEnd> targets = arc.getTargetFragments();
logger.debug("Arc " + arc.getFragmentIndex() + " has " + targets.getLength() + " targets.");
for (ArcEnd end: targets) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment target = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,this,target);
} else {
relationship = new RelationshipImpl(arc,this,end);
}
networks.addRelationship(relationship);
}
}
arcs = locator.getArcsTo();
logger.debug("Locator " + locator.getFragmentIndex() + " has " + arcs.getLength() + " direct arcs TO it.");
for (Arc arc: arcs) {
FragmentList<ArcEnd> sources = arc.getSourceFragments();
logger.debug("Arc " + arc.getFragmentIndex() + " has " + sources.getLength() + " sources.");
for (ArcEnd end: sources) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment source = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,source,this);
} else {
relationship = new RelationshipImpl(arc,end,this);
}
networks.addRelationship(relationship);
}
}
}
return networks;
}
/**
* @see org.xbrlapi.Fragment#getNetworksWithArcrole(String)
*/
public Networks getNetworksWithArcrole(String arcrole) throws XBRLException {
logger.debug("Getting networks for fragment " + getFragmentIndex() + " and arcrole " + arcrole);
Networks networks = new NetworksImpl();
Relationship relationship = null;
// If we have a resource, it could be related directly via arcs to relatives.
if (this.isa("org.xbrlapi.impl.ResourceImpl")) {
FragmentList<Arc> arcs = ((ArcEnd) this).getArcsFromWithArcrole(arcrole);
for (Arc arc: arcs) {
FragmentList<ArcEnd> targets = arc.getTargetFragments();
for (ArcEnd end: targets) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment target = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,this,target);
} else {
relationship = new RelationshipImpl(arc,this,end);
}
networks.addRelationship(relationship);
}
}
arcs = ((ArcEnd) this).getArcsToWithArcrole(arcrole);
for (Arc arc: arcs) {
FragmentList<ArcEnd> sources = arc.getSourceFragments();
for (ArcEnd end: sources) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment source = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,source,this);
} else {
relationship = new RelationshipImpl(arc,end,this);
}
networks.addRelationship(relationship);
}
}
}
// Next get the locators for the fragment to find indirect relatives
FragmentList<Locator> locators = this.getReferencingLocators();
for (Locator locator: locators) {
FragmentList<Arc> arcs = locator.getArcsFromWithArcrole(arcrole);
for (Arc arc: arcs) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -